So I’m trying to interface with an API but I’m starting to tear my hair out trying to figure out this web hook business. I’ve succeeded with making curl calls that are registered and responds correctly but I cannot for the life of me figure out web hooks. So I would love to get some input.
Let’s start with the GET part, so I have a API which I can call using the url and a (Authorization: Bearer TOKEN) what I get back is a JSON formatted string which includes for example humidity and the value of it. So what I wanted to do is solve the riddle of how to extract the humidity data from the JSON response and being able to use it via the spark core.
Curl request example:
curl -H "Authorization: Bearer XYXXXX" "https://api.randomcompanyexample.com/v1/readings/?sensor_type=2&device=XYZZZ&limit=1"
Response:
{
"meta": {
"limit": 1,
"next": "/v1/readings/?device=XYZZZZ&sensor_type=2&limit=1&offset=1",
"offset": 0,
"previous": null,
"total_count": 3599
},
"objects": [
{
"created": "2015-03-25T16:25:20",
"device": "/v1/devices/XYZZZ/",
"id": XYZZZZ,
"resource_uri": "/v1/readings/XYZZZZ/",
"sensor_type": {
"id": 2,
"name": "temperature",
"resource_uri": "/v1/sensors/2/"
},
"value": "20.4965267181"
}
]
Second problem is having the spark core issue a PATCH command via the web hooks, this is to trigger for example a device to turn off/on or change modes via the HTTP calls from the Spark.
Curl example:
curl --request PATCH --data-binary '{"current_mode":"\/v1\/modes\/3\/"}' -H "Authorization: Bearer XYZZZZ" -H "Content-Type: application/json; charset=utf-8" https://api. api.randomcompanyexample.com.com/v1/locations/XYZZZ/
No response is given but after “modes” the number 3 sets the mode of the device, so I want to be able to send 1,2 or 3 as a variable from the spark core.