Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Hi Everyone,
Does anyone know how can I add alert to a "Thing" property with REST API calls?
So, What I would like to do is to use AddOrUpdateAlert service and make a POST request to add an alert and I would like to send the following JSON:
{
alertType: "Above",
alertName: "tc1alert,
property: "tc1",
description: "tc1 alert desc.",
attributes: ????
}
What confuses me is "attributes" field of this service, seems like I need to use an INFOTABLE for that field. But I don't know how I can do that,
Can anyone guide me about that?
Thanks,
Mustafa
It is rather complicated, but you should be able to form that infotable using JSON
Sorry I've never done this using the REST API.
To make it easier, you can create a wrapper service that does the heavy lifting and takes the inputs as regular parameters.
Thanks for the answer.
I actually dont know what to put in that info table. What fields do I need to put?
All I want is to pass a number and get alerted when that number is reached in the sensor. (and doing all that with one REST API call)
What do you think it could be?
Thanks again,
Mustafa
I work with Mustafa. I just worked out the REST call to add an alert via REST/JSON, adding here for others that might be curious.
POST /Thingworx/Things/<TheThing>/Services/AddOrUpdateAlert?appKey=<APP_KEY> HTTP/1.1
Accept: application/json
Content-Type: application/json
Host: <THE_HOST>
Connection: close
User-Agent: Paw/2.2.9 (Macintosh; OS X/10.11.3) GCDHTTPRequest
Content-Length: 859
{
"property": "tc1",
"alertType": "Above",
"alertName": "Temp1High",
"description": "Temp1HighDesc",
"enabled": true,
"priority": 1,
"persistent": true,
"attributes": {
"rows": [
{
"limitInclusive": true,
"limit": 20
}
],
"dataShape": {
"fieldDefinitions": {
"limitInclusive": {
"name": "limitInclusive",
"aspects": {
"defaultValue": true,
"friendlyName": "Include Limit?"
},
"description": "Limit includes value",
"baseType": "BOOLEAN",
"ordinal": 1
},
"limit": {
"name": "limit",
"aspects": {
"friendlyName": "Limit"
},
"description": "Limit to compare",
"baseType": "LONG",
"ordinal": 0
}
}
}
}
}
Awesome. For simplicity and security reasons I do recommend using a 'wrapping' service.