I’m working on a .net app for interacting with the new cloud API. I’m able to do the GET functions just fine. However, when I try a post function, I get a 403 error. I’m for sure adding the token to the header. Here’s an example of the JSON and URL.
https://api.smartthings.com/v1/devices/0ec6f737-33e2-4922-9ece-b94082646866/events
{“deviceEvents”: [{“component” : “main”,“capability”: “powerMeter”,“attribute”: “power”,“value”: 101,“unit”: “W”}]}
Here’s the code (token is defined but not included for obvious reasons)
Private Function SendRequest(url As String, jsonString As String) As String
Dim uri As Uri = New Uri(url)
Dim req As WebRequest = WebRequest.Create(uri)
Dim jsonDataBytes = Encoding.UTF8.GetBytes(jsonString)
req.Headers.Add("Authorization", "Bearer: " & token)
req.ContentType = "application/json"
req.Method = "POST"
req.ContentLength = jsonDataBytes.Length
Dim stream = req.GetRequestStream()
stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
stream.Close()
Dim response = req.GetResponse().GetResponseStream()
Dim reader As New StreamReader(response)
Dim res = reader.ReadToEnd()
reader.Close()
response.Close()
Return res
End Function