API flow for new OTAA devices

Hey folks,

I’m trying to work out the flow of data when creating a new OTAA device via the API.

So far, it seems to be that I should call GET /devices to confirm that the device name/devEui is unique, then POST /devices to create the device.

I then need to add the AppKey for that particular device, so should I be calling POST /devices/<DEV EUI>/keys?

I’ve got a Python script that should do this, however it fails at the final step saying that it can’t find the device, even though the GET /devices shows the device as existing.

If it’s a one time thing, I don’t think there’s any need to list the devices before trying to create it as you’ll get a very explicit error from your POST request:

{error: "object already exists", message: "object already exists", code: 6, details: []}

That said, I can see it being useful to fetch all taken EUIs and have them available for checks before trying to create if you are generating random EUIs, creating a lot of the devices or something like that.

The flow you describe is correct,so I’m guessing maybe you tried to set the keys before the device creation was done? I just tested this and it works:

POST to /api/devices with:

{device: {
	applicationID: "2"
	description: "Testing device 0"
	devEUI: "0101010101010100"
	deviceProfileID: "c659e2a9-7220-4414-8a64-4f02d67bbe92"
	name: "test0"
	}
}

After getting an empty response, which means everything went ok:

POST to /api/devices/0101010101010100/keys with:

{deviceKeys: {nwkKey: "01010101010101000101010101010100", devEUI: "0101010101010100"}}

And that’s it.

Thanks, I thought that was what my code was doing, but perhaps it’s not.

I’ll check it later…

I was sending the wrong values when creating the keys.

nwkKey should be the Application Key and appKey should be 00000000000000000000000000000000

Working now, thanks.

Hi, is there any chance you could share that script with me ? I am trying to implement a very simillar solution but my knowledge on python and APIs is very limited and i don’t think i can make it from scratch