TheThingsArchive / ttn

The Things Network Stack V2
https://www.thethingsnetwork.org
MIT License
463 stars 276 forks source link

Unable to create device thanks to HTTP API #770

Closed Oliv4945 closed 4 years ago

Oliv4945 commented 4 years ago

This is a bug report for the backend

What do you want to do?

Add a device to an application thanks to HTTP API

What steps did you take?

Do a POST request to http://eu.thethings.network:8084/applications/my_app_id/devices/my_dev_id with content

{
   "app_id":"my_app_id",
   "description":"*****",
   "dev_id":"my_dev_id",
   "lorawan_device":{
      "activation_constraints":"local",
      "app_eui":"*****",
      "app_id":"my_app_id",
      "app_key":"*****",
      "dev_eui":"*****",
      "dev_id":"my_dev_id",
      "disable_f_cnt_check":false,
      "f_cnt_down":0,
      "f_cnt_up":0,
      "uses32_bit_f_cnt":true
   }
}

What went wrong or what is missing?

Answer is permission denied, also hivemind_dev_1 is not my app_id

{
   "error":"permission denied: Broker did not set device: permission denied: NetworkServer did not set device: permission denied: No \"devices\" rights to Application \"hivemind_dev_1\"",
   "message":"permission denied: Broker did not set device: permission denied: NetworkServer did not set device: permission denied: No \"devices\" rights to Application \"hivemind_dev_1\"",
   "code":2
}

If think that my request is ok as I get the right answer when I manually create the device in the console and do a GET request to http://eu.thethings.network:8084/applications/my_app_id/devices/my_dev_id. My application key has all rights selected in the web console

htdvisser commented 4 years ago

It looks like the AppEUI/DevEUI combination is already taken by another device in this NetworkServer. That device seems to be registered in hivemind_dev_1, and you indeed don't have permission to update it.

Oliv4945 commented 4 years ago

Hi,

What is surprising is that I can register the device with same AppEui/DevEui in the console, but not the API

thezenox commented 4 years ago

I am facing the same problem (using node.js, but don't matter). Tried generating different AppEuis and DevEuis, all with permission denied: No "devices" rights to Application "ttn-tools" -also not mine. register in web console works with same parameters.

BTW: why is this closed? No solution yet. https://www.thethingsnetwork.org/forum/t/no-devices-rights-to-application/20383 https://www.thethingsnetwork.org/forum/t/failed-to-register-device-no-devices-right-to-application-xxx/28597/8

Remboooo commented 4 years ago

I was facing the same problem: could register the device just fine in the console, but got this error through the API. Using the console to change the handler for the application over from ttn-handler-eu to digitalcatapult-uk-handler fixed it for me.

EDIT: apparently digitalcatapult just does less error checking; the call I was doing ended up making devices with empty DevEUI, empty AppEUI, etc, because the JSON format I was supplying was incorrect. Make sure to use the spec in https://www.thethingsnetwork.org/docs/applications/python/api-reference.html#register_device . It seems that the documentation on pypi is outdated and specifies a different format. The JSON you have to supply is significantly different from the format you get back when requesting devices! E.g. you have to use devEui in stead of dev_eui and it is at the top level in stead of inside a lorawan_device field. Seems this error just occurs if you're supplying invalid JSON to the TTN handler.