Skip to content

Commit 2d1cca8

Browse files
authored
Merge pull request #203165 from v-krishnag/orgrest
updates
2 parents 3397d27 + 9191cb6 commit 2d1cca8

File tree

1 file changed

+224
-5
lines changed

1 file changed

+224
-5
lines changed

articles/iot-central/core/howto-manage-organizations-with-rest-api.md

Lines changed: 224 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The IoT Central REST API lets you:
3737
The REST API lets you create organizations in your IoT Central application. Use the following request to create an organization in your application:
3838

3939
```http
40-
PUT https://{subdomain}.{baseDomain}/api/organizations/{organizationId}?api-version=2022-05-31
40+
PUT https://{your app subdomain}.azureiotcentral.com/api/organizations/{organizationId}?api-version=2022-05-31
4141
```
4242

4343
* organizationId - Unique ID of the organization
@@ -90,14 +90,12 @@ The response to this request looks like the following example:
9090
}
9191
```
9292

93-
94-
9593
### Get an organization
9694

9795
Use the following request to retrieve details of an individual organization from your application:
9896

9997
```http
100-
GET https://{subdomain}.{baseDomain}/api/organizations/{organizationId}?api-version=2022-05-31
98+
GET https://{your app subdomain}.azureiotcentral.com/api/organizations/{organizationId}?api-version=2022-05-31
10199
```
102100

103101
The response to this request looks like the following example:
@@ -115,7 +113,7 @@ The response to this request looks like the following example:
115113
Use the following request to update details of an organization in your application:
116114

117115
```http
118-
PATCH https://{subdomain}.{baseDomain}/api/organizations/{organizationId}?api-version=2022-05-31
116+
PATCH https://{your app subdomain}.azureiotcentral.com/api/organizations/{organizationId}?api-version=2022-05-31
119117
```
120118

121119
The following example shows a request body that updates an organization.
@@ -187,6 +185,227 @@ Use the following request to delete an organization:
187185
DELETE https://{your app subdomain}.azureiotcentral.com/api/organizations/{organizationId}?api-version=2022-05-31
188186
```
189187

188+
## Use organizations
189+
190+
### Manage roles
191+
192+
The REST API lets you list the roles defined in your IoT Central application. Use the following request to retrieve a list of application role and organization role IDs from your application. To learn more see, [How to manage IoT Central organizations](howto-create-organizations.md):
193+
194+
```http
195+
GET https://{your app subdomain}.azureiotcentral.com/api/roles?api-version=2022-05-31
196+
```
197+
198+
The response to this request looks like the following example that includes the application role and organization role IDs.
199+
200+
```json
201+
{
202+
"value": [
203+
{
204+
"id": "ca310b8d-2f4a-44e0-a36e-957c202cd8d4",
205+
"displayName": "Administrator"
206+
},
207+
{
208+
"id": "ae2c9854-393b-4f97-8c42-479d70ce626e",
209+
"displayName": "Operator"
210+
},
211+
{
212+
"id": "344138e9-8de4-4497-8c54-5237e96d6aaf",
213+
"displayName": "Builder"
214+
},
215+
{
216+
"id": "c495eb57-eb18-489e-9802-62c474e5645c",
217+
"displayName": "Org Admin"
218+
},
219+
{
220+
"id": "b4935647-30e4-4ed3-9074-dcac66c2f8ef",
221+
"displayName": "Org Operator"
222+
},
223+
{
224+
"id": "84cc62c1-dabe-49d3-b16e-8b291232b285",
225+
"displayName": "Org Viewer"
226+
}
227+
]
228+
}
229+
```
230+
231+
### Create an API token to a node in an organization hierarchy
232+
233+
Use the following request to create Create an API token to a node in an organization hierarchy in your application:
234+
235+
```http
236+
PUT https://{your app subdomain}.azureiotcentral.com/api/apiTokens/{tokenId}?api-version=2022-05-31
237+
```
238+
239+
* tokenId - Unique ID of the token
240+
241+
The following example shows a request body that creates an API token for an organization in a IoT Central application.
242+
243+
```json
244+
{
245+
"roles": [
246+
{
247+
"role": "84cc62c1-dabe-49d3-b16e-8b291232b285",
248+
"organization": "seattle"
249+
}
250+
]
251+
}
252+
```
253+
254+
The request body has some required fields:
255+
256+
|Name|Description|
257+
|----|-----------|
258+
|role |ID of one of the organization roles.|
259+
|organization| ID of the organization|
260+
261+
The response to this request looks like the following example:
262+
263+
```json
264+
{
265+
"id": "token1",
266+
"roles": [
267+
{
268+
"role": "84cc62c1-dabe-49d3-b16e-8b291232b285",
269+
"organization": "seattle"
270+
}
271+
],
272+
"expiry": "2023-07-07T17:05:08.407Z",
273+
"token": "SharedAccessSignature sr=8a0617**********************4c0d71c&sig=3RyX69G4%2FBZZnG0LXOjQv*************e8s%3D&skn=token1&se=1688749508407"
274+
}
275+
```
276+
277+
### Associate a user with a node in an organization hierarchy
278+
279+
Use the following request to create and associate a user with a node in an organization hierarchy in your application. The ID and email must be unique in the application:
280+
281+
```http
282+
PUT https://{your app subdomain}.azureiotcentral.com/api/users/user-001?api-version=2022-05-31
283+
```
284+
285+
In the following request body, the `role` is the ID of one of the organization roles and `organization` is the ID of the organization
286+
287+
```json
288+
{
289+
"id": "user-001",
290+
"type": "email",
291+
"roles": [
292+
{
293+
"role": "84cc62c1-dabe-49d3-b16e-8b291232b285",
294+
"organization": "seattle"
295+
}
296+
],
297+
"email": "[email protected]"
298+
299+
}
300+
```
301+
302+
The response to this request looks like the following example. The role value identifies which role the user is associated with:
303+
304+
```json
305+
{
306+
"id": "user-001",
307+
"type": "email",
308+
"roles": [
309+
{
310+
"role": "84cc62c1-dabe-49d3-b16e-8b291232b285",
311+
"organization": "seattle"
312+
}
313+
],
314+
"email": "[email protected]"
315+
}
316+
```
317+
318+
### Add and associate a device to an organization
319+
320+
Use the following request to associate a new device with an organization
321+
322+
```http
323+
PUT https://{your app subdomain}.azureiotcentral.com/api/devices/{deviceId}?api-version=2022-05-31
324+
```
325+
326+
The following example shows a request body that adds a device for a device template. You can get the `template` details from the device templates page in IoT Central application UI.
327+
328+
```json
329+
{
330+
"displayName": "CheckoutThermostat",
331+
"template": "dtmi:contoso:Thermostat;1",
332+
"simulated": true,
333+
"enabled": true,
334+
"organizations": [
335+
"seattle"
336+
]
337+
}
338+
```
339+
340+
The request body has some required fields:
341+
342+
* `@displayName`: Display name of the device.
343+
* `@enabled`: declares that this object is an interface.
344+
* `@etag`: ETag used to prevent conflict in device updates.
345+
* `simulated`: Whether the device is simulated.
346+
* `template` : The device template definition for the device.
347+
* `organizations` : List of organization IDs that the device is a part of. Currently, you can only associate a device with a single organization.
348+
349+
The response to this request looks like the following example:
350+
351+
```json
352+
{
353+
"id": "thermostat1",
354+
"etag": "eyJoZWFkZXIiOiJcIjI0MDAwYTdkLTAwMDAtMDMwMC0wMDAwLTYxYjgxZDIwMDAwMFwiIiwiZGF0YSI6IlwiMzMwMDQ1M2EtMDAwMC0wMzAwLTAwMDAtNjFiODFkMjAwMDAwXCIifQ",
355+
"displayName": "CheckoutThermostat",
356+
"simulated": true,
357+
"provisioned": false,
358+
"template": "dtmi:contoso:Thermostat;1",
359+
"enabled": true,
360+
"organizations": [
361+
"seattle"
362+
]
363+
364+
}
365+
```
366+
367+
### Add and associate a device group to an organization
368+
369+
Use the following request to create and associate a new device group with an organization.
370+
371+
```http
372+
PUT https://{your app subdomain}.azureiotcentral.com/api/deviceGroups/{deviceGroupId}?api-version=2022-05-31
373+
```
374+
375+
When you create a device group, you define a `filter` that selects the devices to add to the group. A `filter` identifies a device template and any properties to match. The following example creates device group that contains all devices associated with the "dtmi:modelDefinition:dtdlv2" template where the `provisioned` property is true.
376+
377+
```json
378+
{
379+
"displayName": "Device group 1",
380+
"description": "Custom device group.",
381+
"filter": "SELECT * FROM devices WHERE $template = \"dtmi:modelDefinition:dtdlv2\" AND $provisioned = true",
382+
"organizations": [
383+
"seattle"
384+
]
385+
}
386+
```
387+
388+
The request body has some required fields:
389+
390+
* `@displayName`: Display name of the device group.
391+
* `@filter`: Query defining which devices should be in this group.
392+
* `description`: Short summary of device group.
393+
* `organizations` : List of organization IDs that the device is a part of. Currently, you can only associate a device with a single organization.
394+
395+
The response to this request looks like the following example:
396+
397+
```json
398+
{
399+
"id": "group1",
400+
"displayName": "Device group 1",
401+
"description": "Custom device group.",
402+
"filter": "SELECT * FROM devices WHERE $template = \"dtmi:modelDefinition:dtdlv2\" AND $provisioned = true",
403+
"organizations": [
404+
"seattle"
405+
]
406+
}
407+
```
408+
190409
## Next steps
191410

192411
Now that you've learned how to manage organizations with the REST API, a suggested next step is to [How to use the IoT Central REST API to manage data exports.](howto-manage-data-export-with-rest-api.md)

0 commit comments

Comments
 (0)