question

Mario avatar image
Mario asked

AddorUpdateReport - The request was malformed

Hi i am trying to send an AddrOrUpdateReport to Alexa Gateway but i always get the error "The request was malformed". Probably the error is something obious but i can´t find it.

This is the JSON i am sending:

{
    "event": {
        "header": {
            "namespace": "Alexa.Discovery",
            "name": "AddOrUpdateReport",
            "payloadVersion": "3",
            "messageId": "1f45d172-5a26-4a7f-9a3d-9c23557205e5"
        },
        "payload": {
            "endpoints": [
                {
                    "endpointId": "517",
                    "manufacturerName": "Gira",
                    "description": "",
                    "friendlyName": "Techo",
                    "displayCategories": [
                        "LIGHT"
                    ],
                    "cookie": {
                        "dim_s": "1552",
                        "dim_val": "1676",
                        "slot_dim": "1614"
                    },
                    "capabilities": [
                        {
                            "type": "AlexaInterface",
                            "interface": "Alexa",
                            "version": "3"
                        },
                        {
                            "type": "AlexaInterface",
                            "version": "3",
                            "interface": "Alexa.BrightnessController",
                            "properties": {
                                "supported": [
                                    {
                                        "name": "brightness"
                                    }
                                ],
                                "retrievable": true,
                                "proactivelyReported": true
                            }
                        },
                        {
                            "type": "AlexaInterface",
                            "version": "3",
                            "interface": "Alexa.PowerController",
                            "properties": {
                                "supported": [
                                    {
                                        "name": "powerstate"
                                    }
                                ],
                                "retrievable": true,
                                "proactivelyReported": true
                            }
                        }
                    ]
                }
            ],
            "scope": {
                "type": "BearerToken",
                "token": "<mytoken>"
            }
        }
    }
}
alexa smart home
10 |5000

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

KirkC@Amazon avatar image
KirkC@Amazon answered

I reviewed the AddOrUpdateReport event JSON provided and found one minor issue which will definitely result in an error. The "description" value is just an empty string.

I used your own AddOrUpdateReport to test this theory myself and once I input a string value, for example "description": "Techo by Gira", the API call to the Alexa Event Gateway was successful and I received a 202. No other changes were made.

10 |5000

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

Mario avatar image
Mario answered

Thanks for the reply @KirkC@Amazon.

I have tried filling the description field but still get the same error.

In order to debug the problem i tried using the Smart Home Debugger (https://developer.amazon.com/en-US/docs/alexa/smarthome/test-live-debug.html) but i recieve no messages in the "device log" field although i have carefully followed the activation steps specified in the previous link.

This made me think that maybe the message was being sent to the wrong endpoint but after checking i saw the endpoint was "https://api.eu.amazonalexa.com/v3/events" which seems to be suitable one for skills being developed for the es-ES locale.

The last thing i tried was duplicating the ARN endpoint in the "default" field to the Europe specific region, since previously only the default ARN was provided and i thought that could make the difference, however the same error pops out.

Just in case it helps the code i am using to post the message is the following (Python):


ALEXA_GATEWAY = "https://api.eu.amazonalexa.com/v3/events"
event["event"]["payload"]["scope"]["token"] = access_token
headers = {
  
"Content-Type": "application/json",
"Authorization": access_token
}
r = requests.post(ALEXA_GATEWAY,headers = headers, data = json.dumps(event))


Where <event> is filled with the information in the question of this thread.

What am I missing here?



1 comment
10 |5000

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

Alright just found the problem and as it couldn´t be otherwise it is just a silly mistake. If you check the code i posted before, the "Authorization" header is constructed incorrectly. The problems it that i am omitting the type of authorization (Basic or Bearer) the fix would be the following:

headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + access_token
}

Thanks again to @KirkC@Amazon, i guess that "The request was malformed" is missleading since one would think it refers to the body but it also refers to the headers.

1 Like 1 ·