---
title: "Create Device (saveDevice) with credentials"
method: POST
path: "/api/device-with-credentials"
tags: ["device-controller"]
---

# Create Device (saveDevice) with credentials

`POST /api/device-with-credentials`

Create or update the Device. When creating device, platform generates Device Id as [time-based UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address)). Requires to provide the Device Credentials object as well as an existing device profile ID or use "default".
You may find the example of device with different type of credentials below: 

- Credentials type: <b>"Access token"</b> with <b>device profile ID</b> below: 

```json
{
  "device": {
    "name":"Name_DeviceWithCredantial_AccessToken",
    "label":"Label_DeviceWithCredantial_AccessToken",
    "deviceProfileId":{
      "id":"9d9588c0-06c9-11ee-b618-19be30fdeb60",
      "entityType":"DEVICE_PROFILE"
     }
   },
  "credentials": {
    "credentialsType": "ACCESS_TOKEN",
    "credentialsId": "6hmxew8pmmzng4e3une2"
   }
}
```

- Credentials type: <b>"Access token"</b> with  <b>device profile default</b> below: 

```json
{
  "device": {
    "name":"Name_DeviceWithCredantial_AccessToken_Default",
    "label":"Label_DeviceWithCredantial_AccessToken_Default",
    "type": "default"
   },
  "credentials": {
    "credentialsType": "ACCESS_TOKEN",
    "credentialsId": "6hmxew8pmmzng4e3une3"
   }
}
```

- Credentials type: <b>"X509"</b> with <b>device profile ID</b> below: 

Note: <b>credentialsId</b> -  format <b>Sha3Hash</b>, <b>certificateValue</b> - format <b>PEM</b> (with "--BEGIN CERTIFICATE----" and  -"----END CERTIFICATE-").

```json
{
  "device": {
    "name":"Name_DeviceWithCredantial_X509_Certificate",
    "label":"Label_DeviceWithCredantial_X509_Certificate",
    "deviceProfileId":{
      "id":"9d9588c0-06c9-11ee-b618-19be30fdeb60",
      "entityType":"DEVICE_PROFILE"
     }
   },
  "credentials": {
    "credentialsType": "X509_CERTIFICATE",
    "credentialsId": "84f5911765abba1f96bf4165604e9e90338fc6214081a8e623b6ff9669aedb27",
    "credentialsValue": "-----BEGIN CERTIFICATE----- MIICMTCCAdegAwIBAgIUI9dBuwN6pTtK6uZ03rkiCwV4wEYwCgYIKoZIzj0EAwIwbjELMAkGA1UEBhMCVVMxETAPBgNVBAgMCE5ldyBZb3JrMRowGAYDVQQKDBFUaGluZ3NCb2FyZCwgSW5jLjEwMC4GA1UEAwwnZGV2aWNlQ2VydGlmaWNhdGVAWDUwOVByb3Zpc2lvblN0cmF0ZWd5MB4XDTIzMDMyOTE0NTYxN1oXDTI0MDMyODE0NTYxN1owbjELMAkGA1UEBhMCVVMxETAPBgNVBAgMCE5ldyBZb3JrMRowGAYDVQQKDBFUaGluZ3NCb2FyZCwgSW5jLjEwMC4GA1UEAwwnZGV2aWNlQ2VydGlmaWNhdGVAWDUwOVByb3Zpc2lvblN0cmF0ZWd5MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE9Zo791qKQiGNBm11r4ZGxh+w+ossZL3xc46ufq5QckQHP7zkD2XDAcmP5GvdkM1sBFN9AWaCkQfNnWmfERsOOKNTMFEwHQYDVR0OBBYEFFFc5uyCyglQoZiKhzXzMcQ3BKORMB8GA1UdIwQYMBaAFFFc5uyCyglQoZiKhzXzMcQ3BKORMA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZIzj0EAwIDSAAwRQIhANbA9CuhoOifZMMmqkpuld+65CR+ItKdXeRAhLMZuccuAiB0FSQB34zMutXrZj1g8Gl5OkE7YryFHbei1z0SveHR8g== -----END CERTIFICATE-----"
   }
}
```

- Credentials type: <b>"MQTT_BASIC"</b> with <b>device profile ID</b> below: 

```json
{
  "device": {
    "name":"Name_DeviceWithCredantial_MQTT_Basic",
    "label":"Label_DeviceWithCredantial_MQTT_Basic",
    "deviceProfileId":{
      "id":"9d9588c0-06c9-11ee-b618-19be30fdeb60",
      "entityType":"DEVICE_PROFILE"
     }
   },
  "credentials": {
    "credentialsType": "MQTT_BASIC",
    "credentialsValue": "{\"clientId\":\"5euh5nzm34bjjh1efmlt\",\"userName\":\"onasd1lgwasmjl7v2v7h\",\"password\":\"b9xtm4ny8kt9zewaga5o\"}"
   }
}
```

- You may find the example of <b>LwM2M</b> device and <b>RPK</b> credentials below: 

Note: LwM2M device - only existing device profile ID (Transport configuration -> Transport type: "LWM2M".

```json
{
  "device": {
    "name":"Name_LwRpk00000000",
    "label":"Label_LwRpk00000000",
    "deviceProfileId":{
      "id":"a660bd50-10ef-11ee-8737-b5634e73c779",
      "entityType":"DEVICE_PROFILE"
     }
   },
  "credentials": {
    "credentialsType": "LWM2M_CREDENTIALS",
    "credentialsId": "LwRpk00000000",
    "credentialsValue":
       "{\"client\":{ \"endpoint\":\"LwRpk00000000\", \"securityConfigClientMode\":\"RPK\", \"key\":\"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEUEBxNl/RcYJNm8mk91CyVXoIJiROYDlXcSSqK6e5bDHwOW4ZiN2lNnXalyF0Jxw8MbAytnDMERXyAja5VEMeVQ==\"   }, \"bootstrap\":{ \"bootstrapServer\":{ \"securityMode\":\"RPK\", \"clientPublicKeyOrId\":\"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEUEBxNl/RcYJNm8mk91CyVXoIJiROYDlXcSSqK6e5bDHwOW4ZiN2lNnXalyF0Jxw8MbAytnDMERXyAja5VEMeVQ==\", \"clientSecretKey\":\"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgd9GAx7yZW37autew5KZykn4IgRpge/tZSjnudnZJnMahRANCAARQQHE2X9Fxgk2byaT3ULJVeggmJE5gOVdxJKorp7lsMfA5bhmI3aU2ddqXIXQnHDwxsDK2cMwRFfICNrlUQx5V\"}, \"lwm2mServer\":{ \"securityMode\":\"RPK\", \"clientPublicKeyOrId\":\"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEUEBxNl/RcYJNm8mk91CyVXoIJiROYDlXcSSqK6e5bDHwOW4ZiN2lNnXalyF0Jxw8MbAytnDMERXyAja5VEMeVQ==\", \"clientSecretKey\":\"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgd9GAx7yZW37autew5KZykn4IgRpge/tZSjnudnZJnMahRANCAARQQHE2X9Fxgk2byaT3ULJVeggmJE5gOVdxJKorp7lsMfA5bhmI3aU2ddqXIXQnHDwxsDK2cMwRFfICNrlUQx5V\"}} }"
   }
}
```

Remove 'id', 'tenantId' and optionally 'customerId' from the request body example (below) to create new Device entity. 

Available for users with 'TENANT_ADMIN' or 'CUSTOMER_USER' authority.

## Query parameters

- `nameConflictPolicy` 'FAIL' | 'UNIQUIFY'
- `uniquifySeparator` string
- `uniquifyStrategy` 'RANDOM' | 'INCREMENTAL'

## Request body

- SaveDeviceWithCredentialsRequest — The JSON object with device and credentials. See method description above for example.
  - `device` Device, required
    - `id` DeviceId
      - `id` string, uuid, required — ID of the entity, time-based UUID v1
      - `entityType` 'DEVICE', required — string
    - `createdTime` integer — Timestamp of the device creation, in milliseconds
    - `tenantId` TenantId
      - `id` string, uuid, required — ID of the entity, time-based UUID v1
      - `entityType` 'TENANT', required — string
    - `customerId` CustomerId
      - `id` string, uuid, required — ID of the entity, time-based UUID v1
      - `entityType` 'CUSTOMER', required — string
    - `name` string, required — Unique Device Name in scope of Tenant
    - `type` string — Device Profile Name
    - `label` string — Label that may be used in widgets
    - `deviceProfileId` DeviceProfileId, required
      - `id` string, uuid, required — ID of the entity, time-based UUID v1
      - `entityType` 'DEVICE_PROFILE', required — string
    - `firmwareId` OtaPackageId
      - `id` string, uuid, required — ID of the entity, time-based UUID v1
      - `entityType` 'OTA_PACKAGE', required — string
    - `softwareId` OtaPackageId
      - `id` string, uuid, required — ID of the entity, time-based UUID v1
      - `entityType` 'OTA_PACKAGE', required — string
    - `version` integer
    - `additionalInfo` unknown
    - `deviceData` DeviceData
      - `configuration` DefaultDeviceConfiguration
        - `type` string, required
      - `transportConfiguration` union — Device transport configuration used to connect the device
        - CoapDeviceTransportConfiguration
          - `type` string, required
          - `powerMode` 'PSM' | 'DRX' | 'E_DRX'
          - `psmActivityTimer` integer
          - `edrxCycle` integer
          - `pagingTransmissionWindow` integer
        - DefaultDeviceTransportConfiguration
          - `type` string, required
        - Lwm2mDeviceTransportConfiguration
          - `type` string, required
          - `powerMode` 'PSM' | 'DRX' | 'E_DRX'
          - `psmActivityTimer` integer
          - `edrxCycle` integer
          - `pagingTransmissionWindow` integer
        - MqttDeviceTransportConfiguration
          - `type` string, required
        - SnmpDeviceTransportConfiguration
          - `type` string, required
          - `host` string
          - `port` integer
          - `protocolVersion` 'V1' | 'V2C' | 'V3'
          - `community` string
          - `username` string
          - `securityName` string
          - `contextName` string
          - `authenticationProtocol` 'SHA_1' | 'SHA_224' | 'SHA_256' | 'SHA_384' | 'SHA_512' | 'MD5'
          - `authenticationPassphrase` string
          - `privacyProtocol` 'DES' | 'AES_128' | 'AES_192' | 'AES_256'
          - `privacyPassphrase` string
          - `engineId` string
  - `credentials` DeviceCredentials, required — A JSON value representing the device credentials.
    - `id` DeviceCredentialsId, required
      - `id` string, uuid, required — string
    - `createdTime` integer — Timestamp of the device credentials creation, in milliseconds
    - `deviceId` DeviceId, required
      - `id` string, uuid, required — ID of the entity, time-based UUID v1
      - `entityType` 'DEVICE', required — string
    - `credentialsType` 'ACCESS_TOKEN' | 'X509_CERTIFICATE' | 'MQTT_BASIC' | 'LWM2M_CREDENTIALS' — Type of the credentials
    - `credentialsId` string, required — Unique Credentials Id per platform instance. Used to lookup credentials from the database. By default, new access token for your device. Depends on the type of the credentials.
    - `credentialsValue` string — Value of the credentials. Null in case of ACCESS_TOKEN credentials type. Base64 value in case of X509_CERTIFICATE. Complex object in case of MQTT_BASIC and LWM2M_CREDENTIALS
    - `version` integer

## Response `200`

OK

- Device
  - `id` DeviceId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'DEVICE', required — string
  - `createdTime` integer — Timestamp of the device creation, in milliseconds
  - `tenantId` TenantId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'TENANT', required — string
  - `customerId` CustomerId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'CUSTOMER', required — string
  - `name` string, required — Unique Device Name in scope of Tenant
  - `type` string — Device Profile Name
  - `label` string — Label that may be used in widgets
  - `deviceProfileId` DeviceProfileId, required
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'DEVICE_PROFILE', required — string
  - `firmwareId` OtaPackageId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'OTA_PACKAGE', required — string
  - `softwareId` OtaPackageId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'OTA_PACKAGE', required — string
  - `version` integer
  - `additionalInfo` unknown
  - `deviceData` DeviceData
    - `configuration` DefaultDeviceConfiguration
      - `type` string, required
    - `transportConfiguration` union — Device transport configuration used to connect the device
      - CoapDeviceTransportConfiguration
        - `type` string, required
        - `powerMode` 'PSM' | 'DRX' | 'E_DRX'
        - `psmActivityTimer` integer
        - `edrxCycle` integer
        - `pagingTransmissionWindow` integer
      - DefaultDeviceTransportConfiguration
        - `type` string, required
      - Lwm2mDeviceTransportConfiguration
        - `type` string, required
        - `powerMode` 'PSM' | 'DRX' | 'E_DRX'
        - `psmActivityTimer` integer
        - `edrxCycle` integer
        - `pagingTransmissionWindow` integer
      - MqttDeviceTransportConfiguration
        - `type` string, required
      - SnmpDeviceTransportConfiguration
        - `type` string, required
        - `host` string
        - `port` integer
        - `protocolVersion` 'V1' | 'V2C' | 'V3'
        - `community` string
        - `username` string
        - `securityName` string
        - `contextName` string
        - `authenticationProtocol` 'SHA_1' | 'SHA_224' | 'SHA_256' | 'SHA_384' | 'SHA_512' | 'MD5'
        - `authenticationPassphrase` string
        - `privacyProtocol` 'DES' | 'AES_128' | 'AES_192' | 'AES_256'
        - `privacyPassphrase` string
        - `engineId` string

---

[API](https://skmtc.net/thingsboard/apis/thingsboard-rest-api.md) · [All operations](https://skmtc.net/thingsboard/apis/thingsboard-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/thingsboard/thingsboard-rest-api/revisions/40169ccdec5c/schema)
