Lambda SmartApp error during configuration initialization phase


#1

Hi,

I’m trying to get a SmartApp to work via AWS Lambda integration and can’t get passed the configuration initialization phase.

https://smartthings.developer.samsung.com/develop/guides/smartapps/lifecycles.html#CONFIGURATION

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:

Here’s what I get in the SmartThing’s app (beginning app name cutout):

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.

Thanks in advanced…


(Eric Rodewald) #2

What does your app return for the page with the ID of 1? Feel free to trim out superfluous/sensitive data. Structure and keys being important.


#3

The response is in the screen shot provided, see response body section. I never get a request after returning the above response.


(Paul) #4

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?


(Eric Rodewald) #5

Yes, that was mostly out of curiosity, to see if his PAGE object will be structured correctly.

@djkrite, you should try removing the “list” permissions (l:entity) from your configuration response, as well as the installedapps entity permissions.


#6

OK, I’ll try removing those. I return the above response and nothing happens after that expect the error on the SmartThings app.


(Eric Rodewald) #7

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.


#8

I have an actual app. I respond with the INITIALIZE response and never get anything after that, so the next request doesn’t come in for me to create a response. I don’t get the https://smartthings.developer.samsung.com/develop/guides/smartapps/configuration.html#PAGE-phase request.

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:

{
    "configurationData": {
        "initialize": {
            "name": "Event Receiver App",
            "description": "Event subscriptions service to send device events.",
            "id": "d06694f8-b4e3-41e9-97ca-88b8f6b065dd",
            "permissions": [
                "r:locations:*",
                "w:schedules",
                "r:schedules",
                "l:devices",
                "r:devices:*"
            ],
            "firstPageId": "1"
        }
    }
}

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.


(Jim Anderson) #9

Hi @djkrite,

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.


#10

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}}

The response I returned:

{
    "configurationData": {
        "initialize": {
            "name": "Event Receiver App",
            "description": "Event subscriptions service to send device events.",
            "id": "d06694f8-b4e3-41e9-97ca-88b8f6b065dd",
            "permissions": [
                "r:locations:*",
                "w:schedules",
                "r:schedules",
                "l:devices",
                "r:devices:*"
            ],
            "firstPageId": "1"
        }
    }
}

#11

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.

Thank you!