| title | Manage users and roles with the Azure IoT Central REST API |
|---|---|
| description | How to use the IoT Central REST API to manage users and roles in an application and control access to resources |
| author | dominicbetts |
| ms.author | dobett |
| ms.date | 10/22/2024 |
| ms.topic | how-to |
| ms.service | azure-iot-central |
| services | iot-central |
The IoT Central REST API lets you develop client applications that integrate with IoT Central applications. You can use the REST API to manage users and roles in your IoT Central application.
Every IoT Central REST API call requires an authorization header. To learn more, see How to authenticate and authorize IoT Central REST API calls.
Note
Operations on users and roles are recorded in the IoT Central audit log.
For the reference documentation for the IoT Central REST API, see Azure IoT Central REST API reference.
To learn how to manage users and roles by using the IoT Central UI, see Manage users and roles in your IoT Central application.
The REST API lets you list the roles defined in your IoT Central application. Use the following request to retrieve a list of role IDs from your application:
GET https://{your app subdomain}.azureiotcentral.com/api/roles?api-version=2022-07-31The response to this request looks like the following example that includes the three built-in roles and a custom role:
{
"value": [
{
"id": "ca310b8d-2f4a-44e0-a36e-957c202cd8d4",
"displayName": "Administrator"
},
{
"id": "ae2c9854-393b-4f97-8c42-479d70ce626e",
"displayName": "Operator"
},
{
"id": "344138e9-8de4-4497-8c54-5237e96d6aaf",
"displayName": "Builder"
},
{
"id": "16f8533f-6b82-478f-8ba8-7e676b541b1b",
"displayName": "Example custom role"
}
]
}Note
This command only shows roles that are associated with an application and not a custom organization level role.
The REST API lets you:
- List the users in an application
- Retrieve the details of an individual user
- Create a user
- Modify a user
- Delete a user
Use the following request to retrieve a list of users from your application:
GET https://{your app subdomain}.azureiotcentral.com/api/users?api-version=2022-07-31The response to this request looks like the following example. The role values identify the role ID the user is associated with:
{
"value": [
{
"id": "91907508-04fe-4349-91b5-b872f3055a95",
"type": "email",
"roles": [
{
"role": "ca310b8d-2f4a-44e0-a36e-957c202cd8d4"
}
],
"email": "[email protected]"
},
{
"id": "dc1c916b-a652-49ea-b128-7c465a54c759",
"type": "email",
"roles": [
{
"role": "ae2c9854-393b-4f97-8c42-479d70ce626e"
}
],
"email": "[email protected]"
},
{
"id": "3ab9375e-d2d9-42da-b419-6ae86a938321",
"type": "email",
"roles": [
{
"role": "344138e9-8de4-4497-8c54-5237e96d6aaf"
}
],
"email": "[email protected]"
},
{
"id": "fc5a250b-83fb-433d-892c-e0a144f68c2b",
"type": "email",
"roles": [
{
"role": "16f8533f-6b82-478f-8ba8-7e676b541b1b"
}
],
"email": "[email protected]"
}
]
}Use the following request to retrieve details of an individual user from your application:
GET https://{your app subdomain}.azureiotcentral.com/api/users/dc1c916b-a652-49ea-b128-7c465a54c759?api-version=2022-07-31The response to this request looks like the following example. The role value identifies the role ID the user is associated with:
{
"id": "dc1c916b-a652-49ea-b128-7c465a54c759",
"type": "email",
"roles": [
{
"role": "ae2c9854-393b-4f97-8c42-479d70ce626e"
}
],
"email": "[email protected]"
}Use the following request to create a user in your application. The ID and email must be unique in the application:
PUT https://{your app subdomain}.azureiotcentral.com/api/users/user-001?api-version=2022-07-31In the following request body, the role value is for the operator role you retrieved previously:
{
"id": "user-001",
"type": "email",
"roles": [
{
"role": "ae2c9854-393b-4f97-8c42-479d70ce626e"
}
],
"email": "[email protected]"
}The response to this request looks like the following example. The role value identifies which role the user is associated with:
{
"id": "user-001",
"type": "email",
"roles": [
{
"role": "ae2c9854-393b-4f97-8c42-479d70ce626e"
}
],
"email": "[email protected]"
}You can also add a service principal user that's useful if you need to use service principal authentication for REST API calls. To learn more, see Add or update a service principal user.
Use the following request to change the role assigned to user. This example uses the ID of the builder role you retrieved previously:
PATCH https://{your app subdomain}.azureiotcentral.com/api/users/user-001?api-version=2022-07-31Request body. The value is for the builder role you retrieved previously:
{
"roles": [
{
"role": "344138e9-8de4-4497-8c54-5237e96d6aaf"
}
]
}The response to this request looks like the following example:
{
"id": "user-001",
"type": "email",
"roles": [
{
"role": "344138e9-8de4-4497-8c54-5237e96d6aaf"
}
],
"email": "[email protected]"
}Use the following request to delete a user:
DELETE https://{your app subdomain}.azureiotcentral.com/api/users/user-001?api-version=2022-07-31Now that you've learned how to manage users and roles with the REST API, a suggested next step is to How to use the IoT Central REST API to manage organizations.