Adding new device using API doesn't work for me

Hi All,

I’m dealing for a while without success trying to add some devices using API.

Following the tutorial and the example on the page simply doesn’t work.

Using the API | The Things Stack for LoRaWAN (thethingsindustries.com)

Below are my commands.

curl --location \
  --header 'Authorization: Bearer NNSXS.SECRET' --header 'Content-Type: application/json' \
  --header 'User-Agent: my-integration/my-integration-version' \
  --request POST \
  --data '{
    "end_device": {
      "ids": {
        "device_id": "eui-000516800010f48a",
        "dev_eui": "000516800010f48a",
        "join_eui": "01203F04E0D5B370"
      },
      "join_server_address": "au1.cloud.thethings.network",
      "network_server_address": "au1.cloud.thethings.network",
      "application_server_address": "au1.cloud.thethings.network"
    },
    "field_mask": {
      "paths": [
        "join_server_address",
        "network_server_address",
        "application_server_address",
        "ids.join_eui",
        "ids.device_id",
        "ids.dev_eui"
      ]
    }
  }' \
  'https://au1.cloud.thethings.network/api/v3/applications/my_app_id/devices/eui-000516800010f48a'


curl --location \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer NNSXS.SECRET' --header 'Content-Type: application/json' \
  --header 'User-Agent: my-integration/my-integration-version' \
  --request PUT \
  --data '{
    "end_device": {
      "supports_join": true,
      "lorawan_version": "MAC_V1_0_2",
      "ids": {
        "device_id": "eui-000516800010f48a",
        "dev_eui": "000516800010f48a",
        "join_eui": "01203F04E0D5B370"
      },
      "lorawan_phy_version": "PHY_V1_0_2_REV_B",
      "frequency_plan_id": "AU_915_928_FSB_1"
    },
    "field_mask": {
      "paths": [
        "supports_join",
        "lorawan_version",
        "ids.device_id",
        "ids.dev_eui",
        "ids.join_eui",
        "lorawan_phy_version",
        "frequency_plan_id"
      ]
    }
  }' \
  'https://au1.cloud.thethings.network/api/v3/ns/applications/my_app_id/devices/eui-000516800010f48a'
curl --location \
  --header 'Authorization: Bearer NNSXS.SECRET' --header 'Content-Type: application/json' \
  --header 'User-Agent: my-integration/my-integration-version' \
  --request PUT \
  --data '{
    "end_device": {
      "ids": {
        "device_id": "eui-000516800010f48a",
        "dev_eui": "000516800010f48a",
        "join_eui": "01203F04E0D5B370"
      }
    },
    "field_mask": {
      "paths": [
        "ids.device_id",
        "ids.dev_eui",
        "ids.join_eui"
      ]
    }
  }' \
  'https://au1.cloud.thethings.network/api/v3/as/applications/my_app_id/devices/eui-000516800010f48a'
curl --location \
  --header 'Authorization: Bearer NNSXS.SECRET' --header 'Content-Type: application/json' \
  --header 'User-Agent: my-integration/my-integration-version' \
  --request PUT \
  --data '{
    "end_device": {
      "ids": {
        "device_id": "eui-000516800010f48a",
        "dev_eui": "000516800010f48a",
        "join_eui": "01203F04E0D5B370"
      },
      "network_server_address": "au1.cloud.thethings.network",
      "application_server_address": "au1.cloud.thethings.network",
      "root_keys": {
        "app_key": {
          "key": "01203F04E08005204303007XXXXXXXX"
        }
      }
    },
    "field_mask": {
      "paths": [
        "network_server_address",
        "application_server_address",
        "ids.device_id",
        "ids.dev_eui",
        "ids.join_eui",
        "root_keys.app_key.key"
      ]
    }
  }' \
  'https://au1.cloud.thethings.network/api/v3/js/applications/my_app_id/devices/eui-000516800010f48a'

Any help will be apreciated.

Regards from Brazil.

Nice commands - but what are the errors you are getting?

Thanks for reply.

the first one as I can see does not register successful.

https://au1.cloud.thethings.network/api/v3/applications/my_app_id/devices/eui-000516800010f48a

All the rest are ok.

When i register on web panel, all 3 get updated, and the first created.

This …

That’s.

I´m not getting no erros.

Just the device get not registered.

If you can do the same commands and give me some north, I appreciate.

So the command gets entered on the command line and cURL has no feedback at all??

Can you add a -v to make it more verbose - or even a --trace to capture every detail.

Here’s some PHP so a different way of sending the data but the JSON is the same:

Here are verbose output:

[root@cpanel ~]# curl -v --location \
>   --header 'Authorization: Bearer NNSXS.SECRET' --header 'Content-Type: application/json' \
>   --header 'User-Agent: my-integration/my-integration-version' \
>   --request POST \
>   --data '{
>     "end_device": {
>       "ids": {
>         "device_id": "eui-000516800010f48a",
>         "dev_eui": "000516800010f48a",
>         "join_eui": "01203F04E0D5B370"
>       },
>       "join_server_address": "au1.cloud.thethings.network",
>       "network_server_address": "au1.cloud.thethings.network",
>       "application_server_address": "au1.cloud.thethings.network"
>     },
>     "field_mask": {
>       "paths": [
>         "join_server_address",
>         "network_server_address",
>         "application_server_address",
>         "ids.join_eui",
>         "ids.device_id",
>         "ids.dev_eui"
>       ]
>     }
>   }' \
>   'https://au1.cloud.thethings.network/api/v3/applications/my_app_id/devices'
* About to connect() to au1.cloud.thethings.network port 443 (#0)
*   Trying 13.238.174.71...
* Connected to au1.cloud.thethings.network (13.238.174.71) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
*       subject: CN=au1.cloud.thethings.network
*       start date: Oct 12 11:01:00 2021 GMT
*       expire date: Jan 10 11:00:59 2022 GMT
*       common name: au1.cloud.thethings.network
*       issuer: CN=R3,O=Let's Encrypt,C=US
> POST /api/v3/applications/my_app_id/devices HTTP/1.1
> Host: au1.cloud.thethings.network
> Accept: */*
> Authorization: Bearer NNSXS.SECRET
> Content-Type: application/json
> User-Agent: my-integration/my-integration-version
> Content-Length: 593
>
* upload completely sent off: 593 out of 593 bytes
< HTTP/1.1 404 Not Found
< date: Sun, 14 Nov 2021 15:47:27 GMT
< server: envoy
< connection: close
< content-length: 0
<
* Closing connection 0
[root@cpanel ~]#

Got a 404 error

So, what is wrong with the url? Allready double check this.

And also tried the php example of this post.

Bit of a “is it plugged in” question, but are you changing this bit to your application id?

Yes. Just changed on post for security reasons.

Did you see the 404 error? Something is wrong with the first url.

https://au1.cloud.thethings.network/api/v3/applications/my_app_id/devices

Regards

Sure, that’s why I asked about the my_app_id.

I’ve a setup on the AU cluster, if you can give me a few hours I can try the PHP I have working on the EU cluster but against the AU cluster.

Okay. I would really appreciate it.

https://au1.cloud.thethings.network/api/v3/ns/applications/my_app_id/devices

Returns

{"code":12,"message":"Not Implemented"}

And not a 404

api/v3/ns/applications/my_app_id/device

This is a PUT not a POST. Which documentation are you referring to here? Also for js and as.

https://au1.cloud.thethings.network/api/v3/applications/my_app_id/devices

That’s a call to the Identity Server which is not present in the au1 cluster. There’s only one Identity Server for TTS CE and that’s in the eu1 cluster.

What documentation are you using to make these requests? I’ll check if those are complete.

Hi Krishna,

I folow this page:

https://www.thethingsindustries.com/docs/getting-started/api/

Regards

2 posts were split to a new topic: Register gateway duplicate EUI warning

Hi there Krishna,

I have arrived on this thread due to the same issue as the original poster and, the problem I had was also that the I was using au1 instead of eu1 for the identity server call.

It seems that the docs have still not yet been updated, as for the identity server example it just gives: “thethings.example.-com”, which for all other instances in the example should just be replaced with “au1.cloud.thethings.-network”.

This inconsistency is kind of confusing and it seems like the “thethings.example.-com” in the identity server call should just be replaced with “eu1.thethings.-network” since it is the only option that works in the first place.

Or at least I think it would at least be useful to mention this this fact in the docs, so more users don’t continue to have this issue.

Sorry about the random hyphens in the links(just pretend they are not there) but It would not let me post otherwise as new users can only post 2 links in a post.

The documentation I am referring to is here:
https://www.thethingsindustries.com/docs/getting-started/api/

Kind Regards,

Max

Hi Max,

Documentation pages have a link “edit on GitHub” that allows you to create an update yourself for which you can submit a pull request. That way you can help improving the open source project.

Hi Jac

Thank you for the reply,

I was unaware that this was option, I will make sure to do that at some point.

Cheers,

Max