Hi, I am trying out the new Rest API’s, and when I am trying to create an app. Here is the my request
curl -X POST https://api.smartthings.com/v1/apps
-H “Authorization: Bearer xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxx”
-H “Content-Type: application/json; charset=utf-8”
-d ‘{“appName”: “xxxx”, “displayName”: “xxxxxx”, “description”: “xxxxxx”, “appType”: “WEBHOOK_SMART_APP”, “webhookSmartApp”: {“targetUrl”: “/smartthings”}}’;
The response I’m getting is
{“requestId”:“305cc382-1b61-c061-174c-503b820b6d5f”,“error”:{“code”:“ConstraintViolationError”,“message”:“The request is malformed.”,“details”:[{“code”:“TargetUnreachableError”,“target”:“http://a3b8cb56.ngrok.io/smartthings",“message”:"Unable to communicate with target.”,“details”:[]}]}}
Here is the thing, I am building the backend in Ruby. Also, I’m not sure, what I need to do when the request comes to my backend. I need a little help understanding. I have an endpoint “/smartthings” defined in my code, these are the paramaters I’m getting
{“lifecycle”=>“PING”, “executionId”=>“305cc382-1b61-c061-174c-503b820b6d5f”, “locale”=>“en”, “version”=>“0.1.0”, “pingData”=>{“challenge”=>“7fc139ef-3b2c-4726-9354-832606b4e0f2”}, “settings”=>{}, “samsung_smartthing”=>{“lifecycle”=>“PING”, “executionId”=>“305cc382-1b61-c061-174c-503b820b6d5f”, “locale”=>“en”, “version”=>“0.1.0”, “pingData”=>{“challenge”=>“7fc139ef-3b2c-4726-9354-832606b4e0f2”}, “settings”=>{}}}
What should I do with this request ?
Appreciate the help.
Thank you.
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
2
I hate to just respond with a link to the Docs; but hoping it might move the discussion forward regardless.
Thank you. However, I found that lifecycle documentation as well, however, what I don’t understand is what should be the targetURL ? Shouldn’t the targetURL be which is pinging the Samsung cloud ? Sorry, If I am asking the wrong questions, new to this.
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
4
I’ve very new to this too, so … just exploring together.
You need to run a server (e.g., node.js with express) or lambdas; with the Endpoints for the callbacks that SmartThings expects (e.g., ping, installed, …). I think those are the “target URLs”.
There are some good examples in Node.js … have you tried them first? I find it is always best to get the example working in my own environment, and then tweak it, change the programming language, etc., bit by bit, until it breaks … rather that trying to build it up until it “works”.
The targetURL is the external URL of your web application. I.e. what you tell the SmartThings API to connect to when it needs to talk to your application to send it events or ask your app to do something. SmartThings will POST a json blob with “lifecycle” : “PING” to your app when you try to register to make sure it is running correctly. If you do get that PING, then your targetURL is correct. Now all you have to do is get your app to reply correctly by sending back the “pingData” variable you received, i.e. reply something like this:
In return you get a JSON blob with all the stuff you need, including a public key so you can ensure future requests to your app is actually coming from SmartThings and an oauth id and secret. Store the info in a safe place.
And in case that wasn’t obvious, your app needs to be running and respond to PING at this point. The API will not give you the credentials needed on the curl-call if the PING is not successful.