Skip to content

Commit 65a609a

Browse files
authored
Added a sample code for creating metadata
1 parent 52f0fc0 commit 65a609a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

articles/industry/agriculture/ingest-historical-telemetry-data-in-azure-farmbeats.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Sensor
269269
}
270270
}
271271
```
272-
The following sample request creates a device. This request has input JSON as payload with the request body.
272+
The following sample request creates a device. This request has input JSON as payload with the request body. Below there is also a sample python script that creates a device model.
273273

274274
```bash
275275
curl -X POST "https://<datahub>.azurewebsites.net/Device" -H
@@ -279,6 +279,22 @@ curl -X POST "https://<datahub>.azurewebsites.net/Device" -H
279279
\"description\": \"Test Device 123\"}" *
280280
```
281281

282+
Below is the sample code in Python. Please note that the access token used in this sample is the same that we received during authentication
283+
284+
```python
285+
import requests
286+
import json
287+
288+
# Got access token - Calling the DeviceModel API
289+
headers = {
290+
"Authorization": "Bearer " + access_token,
291+
"Content-Type" : "application/json"
292+
}
293+
payload = '{"type" : "Node", "productCode" : "TestCode", "ports": [{"name": "port1","type": "Analog"}], "name" : "DummyDevice"}'
294+
response = requests.post(ENDPOINT + "/DeviceModel", data=payload, headers=headers)
295+
```
296+
297+
282298
> [!NOTE]
283299
> The APIs return unique IDs for each instance created. You must retain the IDs to send the corresponding telemetry messages.
284300

0 commit comments

Comments
 (0)