Issues with creating new webhook smartapp

I’ve batted my head against the desk enough with this, so want to see if someone else knows what’s going on. This is my first smartapp. I’m working on getting ST connected to a python app running on my RPi so that I can control a few ancillary devices through custom code.

So I went through the install instructions here: https://smartthings.developer.samsung.com/develop/guides/smartapps/app-registration.html

When I go to create the app by doing the CURL request (which I’m doing in python), I get the below. As you can see, I am POSTing the app as specified, and then a request comes in to do the PING which I respond to, but then in the response of the app creation POST I get a constraints violation with something about a classification and I can’t find anywhere that is even referenced? Any help would be much appreciated!

POST https://api.smartthings.com/v1/apps
Authorization: Bearer <my_token>
Content-Type: application/json; charset=utf-8
Content-Length: 241

{"appName": "tech.blah.blah.blah", "displayName": "home-automation", "description": "Made by someone", "appType": "WEBHOOK_SMART_APP", "webhookSmartApp": {"targetUrl": "https://<my_hostname>/ha/smartthings/webhook"}}

Now incoming POST request comes in…

Host: <my_hostname>
Connection: close
Content-Length: 183
Content-Type: application/json
Accept: application/json
User-Agent: AHC/2.1

{"lifecycle":"PING","executionId":"1B363EDC-E4C0-477E-B9DA-B432626D8F54","locale":"en","version":"0.1.0","pingData":{"challenge":"#####CHALLENGE#####"},"settings":{}}
2019-03-04 05:20:36 - Handling SmartThings lifecycle method PING
Responding with HTTP 200: {'pingData': {'challenge': '#####CHALLENGE#####'}}
2019-03-04 05:20:36 - 192.168.1.123 - - [04/Mar/2019 05:20:36] "POST /smartthings/webhook HTTP/1.0" 200 -

Now I get the response of the app POST request… classifications is no where to be mentioned??

{"requestId":"1B363EDC-E4C0-477E-B9DA-B432626D8F54","error":{"code":"ConstraintViolationError","message":"The request is malformed.","details":[{"code":"SizeError","target":"classifications","message":"classifications must have a size between 1 and 4.","details":[]}]}}

I don’t know if it’s relevant but I’m using the following PING response successfully:
{“statusCode”:0,“pingData”:{“challenge”:"#####CHALLENGE#####"}}

Comparing with your response the only difference I can see is that you don’t have a StatusCode object in your response and I do.

StatusCode isn’t mentioned in the LifeCycle section of the Guide Docs but does appear in the API definition docs here

Mark – thanks for that. I gave it a shot and it still is failing with the classifications message – see below. One question… I wasn’t sure where the HTTP signing came into place. The references are saying I get the public key in a request from ST, but is that later in the flow, or am I suppose to sign the response? I’m at a loss…

-----------START INSTALL ENDPOINT-----------
POST https://api.smartthings.com/v1/apps
Authorization: Bearer <token>
Content-Type: application/json; charset=utf-8
Content-Length: 241

{"appName": "<namespace>.home-automation", "displayName": "home-automation", "description": "Made by AlwaysOn", "appType": "WEBHOOK_SMART_APP", "webhookSmartApp": {"targetUrl": "https://<hostname>/ha/smartthings/webhook"}}
-----------INCOMING REQUEST LOGGING START-----------
Host: <hostname>
X-Real-Ip: 127.0.0.1
X-Forwarded-For: 127.0.0.1
X-Scheme: https
X-Script-Name: /ha
Connection: close
Content-Length: 183
Content-Type: application/json
Accept: application/json
X-St-Correlation: 09D41681-5996-41B3-8936-BC48F9E2F768
X-B3-Traceid: 82db86a46d67812f
X-B3-Spanid: c897e6e8436a9a1b
X-B3-Parentspanid: 4a6a139fcbacea58
X-B3-Sampled: 0
User-Agent: AHC/2.1


{"lifecycle":"PING","executionId":"09D41681-5996-41B3-8936-BC48F9E2F768","locale":"en","version":"0.1.0","pingData":{"challenge":"8371f59d-f2d1-4663-a70b-7a1ae9fe1a67"},"settings":{}}
-----------INCOMING REQUEST LOGGING END-----------
-----------OUTBOUND RESPONSE LOGGING START-----------
200 OK
Content-Type: application/json
Content-Length: 84

{"statusCode": 0, "pingData": {"challenge": "8371f59d-f2d1-4663-a70b-7a1ae9fe1a67"}}
-----------OUTBOUND RESPONSE LOGGING END-----------
{"requestId":"09D41681-5996-41B3-8936-BC48F9E2F768","error":{"code":"ConstraintViolationError","message":"The request is malformed.","details":[{"code":"SizeError","target":"classifications","message":"classifications must have a size between 1 and 4.","details":[]}]}}

Try adding classifications to your request when creating the app:

"classifications": ["AUTOMATION"] 

That should get you past the error you’re seeing when creating the app (or just use the Developer Workspace, which will handle it for you).

Then the response from creating your app will include a public key, which can be used to verify future requests from ST to your app.

Hope that helps, and if you continue to have difficulty don’t hesitate to open a Developer Support ticket.

The SmartApp API signs Lifecycle messages it sends to you but doesn’t require signatures on the responses you send back. When you use the workbench to create the automation the public key (though not the keyID) is displayed on there.

if you create the app using the API instead I believe that the returned App model includes the public key as part of the WebHookSmartApp object (as defined in the SmartThings API) - @Jim should be able to confirm this.

Thanks guys – adding the “classifications” worked for me and successfully returned the app object with the private key. I think it must just be a new requirement that the docs haven’t kept up with. Appreciate the help!

Glad to hear it worked! Apologies for the out-of-date docs - the documentation team is aware and working to address that.

1 Like