Overview
You are looking for instructions on how to create a device using the GraphQL API.
Solution
In order to make the requests through the API, the information below is required. For further details on the API refer to Using the CCAB GraphQL API.
- The Provider ID.
- An Access Token using the credentials from an Account Admin.
To create a new device, one should use the createDevice operation. With this method, one can create a device for an account, and it requires passing some of the parameters mentioned in CreateDeviceInput. Note that it is necessary to know the ID of the account. This ID is used/returned when the account is first created (see Create an Account using the API for further details).
Below is an example payload using API version 10.1 with some relevant points:
- The device value is not being passed so the ID is automatically generated after creation.
- The payload contains the different union types that can be returned from this request.
mutation adddevice {
createDevice(input: {
accountId: "<accountId>",
providerId: "<providerId>"
}) {
... on CreateDevicePayload {
__typename
device {
id
customData
account {
id
balance {
version
value
}
customData
}
}
}
... on AccountNotFound {
accountId
errorCode
errorMessage
}
... on DeviceAlreadyExists {
deviceId
errorCode
errorMessage
}
... on InvalidField {
fieldName
errorCode
errorMessage
}
}
}
If the device is successfully created, the following details are returned.
On the other hand, in case of a problem during creation, the response will contain the error details.