sinricpro / non-sdk-issues

Report non sdk related issues here (Alexa, Google Home, SmartThings, IFTTT, API)
2 stars 0 forks source link

bug when calling create device api command #53

Closed Geromatic closed 1 year ago

Geromatic commented 1 year ago

I tried to add a device using the nodejs command. I am using arduino and json. but when I submit the info to create a device is says name needs to be define yet I already did

{"id":"64042e541bb4e19c11ae4129","name":"hello there","productId":"5c5f72915ef9c024b423a046","roomId":"5c5f796140a15340803141c8"} HTTP Response code: 422 "success" = false "message" = "\"name\" is required"

kakopappa commented 1 year ago

Hi @Geromatic

Since you have not posted the complete code or example code to reproduce the problem I am guessing your parameters are incorrect. Here's an example using nodejs fetch.

fetch("https://api.sinric.pro/api/v1/devices", {
  "headers": {
    "accept": "application/json, text/plain, */*",
    "authorization": "Bearer <TOKEN>" 
  },
  "body": "{\"name\":\"switch1\",\"description\":\"switch2\",\"productId\":\"5c67c4d4268198273c8551d0\",\"roomId\":\"<ROOMID>\",\"accessKeyId\":\"ACCESS_KEY_ID\",\"notifications\":{\"connection\":{\"whenConnected\":false,\"whenDisconnected\":false},\"turned\":{\"whenOn\":false,\"whenOff\":false},\"alert\":{\"enabled\":true}},\"timers\":{\"autoOnOff\":{\"on\":false,\"onInterval\":5,\"off\":false,\"offInterval\":5}},\"energyUsageEstimation\":{\"enabled\":false,\"type\":\"POWER\"}}",
  "method": "POST"
});
kakopappa commented 1 year ago

I think your issue is http.addHeader("Content-Type", "application/x-www-form-urlencoded"); should be http.addHeader("Content-Type", "application/json");

image

also don’t forget to fix

roomId\":\"\",\"accessKeyId\":\"\"

Geromatic commented 1 year ago

ty.

kakopappa commented 1 year ago

you can use

get the list of rooms: https://api.sinric.pro/api/v1/rooms get the list of credential : https://api.sinric.pro/api/v1/credentials/appkeyandsecret

Geromatic commented 1 year ago

one last note. is it because I am using the free account that I get this error

HTTP Response code: {"success":false,"message":"Unauthorized!"}

kakopappa commented 1 year ago

No, Likely missing the authorization http header

On Sun, 5 Mar 2023 at 2:44 PM Scott Bishel @.***> wrote:

one last note. is it because I am using the free account that I get this error

HTTP Response code: {"success":false,"message":"Unauthorized!"}

— Reply to this email directly, view it on GitHub https://github.com/sinricpro/non-sdk-issues/issues/53#issuecomment-1455015618, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZUAK5X6JTNI42CGV4LW2Q75PANCNFSM6AAAAAAVP7G67I . You are receiving this because you commented.Message ID: @.***>

Geromatic commented 1 year ago

It would be nice in the future that Arduino could be used for all the node.js commands. I will think on it :) it would really benefit everyone