question

Chris avatar image
Chris asked

Struggling to get the Deferred Response correct for LockController

I am developing a LockController, however I am getting the following error with the asynchronous response message:

INVALID_REQUEST_EXCEPTION : The request was malformed.

If I look at the documentation, it looks like the synchronous response message and the asynchronous message for a deferred response are identical. If I send the message I created synchronously it works fine (albeit the device hasn't locked since it takes time :)), however, if I send a deferred response message and then asynchronously send the exact same message I sent synchronously, I get an error.

Here's the async message Im sending (looks like the documentation and conforms to the schema):

{
        "context": {
                "properties": [{
                        "namespace": "Alexa.LockController",
                        "name": "lockState",
                        "value": "LOCKED",
                        "timeOfSample": "2018-05-09T17:19:02.86Z",
                        "uncertaintyInMilliseconds": 500
                }]
        },
        "event": {
                "header": {
                        "namespace": "Alexa",
                        "name": "Response",
                        "payloadVersion": "3",
                        "messageId": "328521c5-b545-4bce-a12f-22ce479f51ac-D",
                        "correlationToken": <correlation from original request>
                },
                "endpoint": {
                        "scope": {
                                "type": "BearerToken",
                                "token": <token from original lock request>
                        },
                        "endpointId": "pi-door-lock"
                },
                "payload": {}
        }
}

Any thoughts on what I'm missing?

Thanks

/Chris

alexa smart homeresponsedocumentationlocks
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

roy-1 avatar image
roy-1 answered

Hi Chris,

Thanks for posting. The first thing that I'd recommend would be to check that you're including the correct headers as per the docs:

https://developer.amazon.com/docs/device-apis/alexa-interface.html#response

POST /v3/events HTTP/1.1
Host: api-amazonalexa.com
Authorization: Bearer access-token-from-Amazon
Content-Type: application/json

I'd also check to see that you are indicating the correct estimated deferral in seconds as part of your DeferredResponse. Please check here for an example:

https://developer.amazon.com/docs/device-apis/alexa-interface.html#deferredresponse


It would also be worth double-checking to ensure that your correlation token for this response match your DeferredResponse as well. Hope this helps!

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Chris avatar image
Chris answered

Hi Roy, thanks for following up.

I checked the headers and the correlation token and everything seems correct. Since this is a garage door, it takes about 20 seconds to go from open to closed and vice versa. There is however, an edge case. If the door is partially open I may have to wait up to 40 seconds to get it in the correct state. I set the estimated deferral to 30 seconds - not sure what impact this has on the rest of the infrastructure on your side.

Thanks

Chris

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

roy-1 avatar image
roy-1 answered

Hi Chris,

Thanks for the additional info. Please try aligning the time on your deferred response's estimatedDeferralInSeconds with the following asynchronous response POST and see if you still receive an error.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.