I’m trying to get a SmartApp to work via AWS Lambda integration and can’t get passed the configuration initialization phase.
On the new SmartThings app for iPhone I click on “Automations” and can see my SmartApp, after clicking on the SmartApp node in automations, a request is delivered to my AWS Lambda, my Lambda responds with the correct body, statusCode, isBase64Encoded, and headers, then I get this message in the SmartThings app, “Something went wrong. Please try to install the SmartApp again.”. I know my Lambda is responding correctly via testing a POST with the AWS API Gateway testing interface. Here’s a screen shot of a test POSTing a sample SmartThings request to the Lambda and the response back:
Is there logging anywhere, so I can see why it’s breaking and do SmartApps work with personal tokens? This SmartApp was created via the SmartThings API with a personal token.
I think Eric is asking what does your app return for page 1, not “what page Id does it say is first”. So I’m guessing that after doing the initial config the mobile app then requests the content of page 1 and you haven’t implemented that?
It’s not clear to me yet if you’ve got an actual app powering this or if you just set up a basic static response in your AWS API Gateway to test this, but the endpoint app will be called once with the configurationData.phase of INITIALIZE and then a second time with a phase of PAGE. The second will is what builds a page - if you don’t respond to that, it won’t be able to show the configuration and will show an error.
I tried your suggests and removed the installedApps and entity permissions, but it still shows the same error. This is how I respond to the INITIALIZE phase request:
Should appId be a UUID thats same across multiple installations or is unique per installation?
In regards to the API Gateway test interface above I copy the request that SmartThings sends me and use it as the body of a test POST against my Lambda, so I can see if my app is responding correctly according to AWS Lambda framework. This rules out that my core Lambda response code is incorrect and points me look somewhere else for a solution.
There is a new logging feature in the Developer Workspace that aims to help troubleshoot these types of issues. It does require that you create your app in the workspace, instead of via the API with a personal token. You will probably want to test installation through the new SmartThings app instead of Classic.
Typically, these types of errors during initialization or configuration are due to one of the following:
Permissions/Scopes issues
The permissions requested in your code’s permissions array must match (or be a subset of) the OAuth scopes on your app record itself. Requesting a permission in your app’s initialize config that is not on the OAuth scopes of the app record, or that is not valid, would cause an error similar to this. The logging should catch these types of errors for you to see.
Typo/Invalid response
If the JSON response from your app does not conform to the expected format, or if the response contains typos for certain field, there would be an error similar to what you are seeing. Again, the logging in the workspace is intended to catch these type of errors.
Both of these causes are difficult to debug without logging (as you are seeing), so check out the logger and hopefully that will help identify the issue in your case.
OK. I was able to get live logging working with a new app after enabling developer mode and this is what it says:
{"eventType":"EXECUTION_RESULT_EVENT","locationId":"6b04ce93-b322-4543-b51c-af07c2a66cb5","appId":"b9bfa5be-1824-4c79-a87f-4408736cb840","installedAppId":"7f3bdf55-d6f2-4a7e-b342-e71d6578a435","appType":"LAMBDA_SMART_APP","displayName":"Event Receiver1","executionType":"CONFIGURATION","statusCode":200,"reasonCode":null,"reasonMessage":null,"executionStartTime":"2018-11-20T21:41:08.64Z","executionDuration":1811,"time":"2018-11-20T21:41:09.875Z","error":{"code":"ConstraintViolationError","message":"The request is malformed.","target":"","details":[{"code":"NotValidValue","message":"configurationData is not a valid value.","target":"configurationData","details":[]}]},"rateLimit":{"status":"UNDER","current":1,"remaining":199}}
Okay. After more testing I found out that an “API Gateway” is not required for the SmartThings Lambda to function. I was under the assumption that a gateway was needed for this, but that is incorrect. Now everything is working as the I’m returning the response in a regular Lambda style as opposed to adhering to the API Gateway specs.