Create device batch with custom IDs

Description

This method creates devices with custom IDs. The request object takes an array of device IDs, an optional list of preshared keys, and an optional tags parameter. Device IDs is an array of valid device IDs as strings, preSharedKeys is an array of length 32 strings of valid preshared keys, and tags is of type map encoded in json. If the preSharedKeys parameter is unused, the API will generate a key for each device, otherwise, devices are assigned a key based on the array index. Length of preSharedKeys must equal length of deviceId.

The request returns a batch ID as a reference to all devices created with the specific call, and a “keys” array of device ID’s, their key, and their tags. If the list of device ID’s contains an already existing device ID, or an invalid device ID, the entire list is rejected, and an error is returned.

Request

POST /v1/domains/:domain/keys/custom-devices
{
  deviceIds: string[],
  preSharedKeys: string[],
  tags?: {
    [key: string]: string
  }
}

Response

Successful response contains the following JSON formated body:

{
  batchId: number,
  keys: {
    deviceId: string,
    preSharedKey: string,
    tags: {
      [key: string]: string
    }
  }[]
}

Response Status codes:

  • 200 on success

Request headers

This request must have the following headers:

  • Authorization: bearer <ApiKey>
  • X-Nabto-Organization: <organizationId>
  • Content-Type: application/json

Example

Request

curl -XPOST "https://api.cloud.nabto.com/v1/domains/:domain/keys/custom-devices" \
  -H "Authorization: Bearer <ApiKey>" \
  -H "X-Nabto-Organization: <OrganizationId>" \
  -H "Content-Type: application/json" \
  -d '{ deviceIds:[ "a.mydomain.example.net",...], preSharedKeys:[ "01010101010101010101010101010101",...], tags: {"foo": "bar" }}'

Response

{
   batchId: 42,
  keys: [{
     deviceId: "a.mydomain.example.net",
    preSharedKey: "01010101010101010101010101010101",
    tags: {
      "foo": "bar" 
    }
     
  },
  ...]
}