Sending a message with ContentType application/json won't work

0

I'm trying to send a message with a JSON payload using boto3:

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/connectparticipant/client/send_message.html

response = client.send_message(
        ContentType='application/json',
        Content=json.dumps({'key': 'value'}),
        ConnectionToken=connection_token
    )

However, I always get this error:

An error occurred (ValidationException) when calling the SendMessage operation: Specified request parameter(s) are invalid.

If I switch the ContentType to text/plain, everything works fine. Is this a bug, or am I making a mistake?

Edit: Fixed typo

asked a year ago354 views
1 Answer
0

Looking at the code you provided, it looks like you are missing a closing single quotation mark in the json.dumps line. The 'value should be 'value'. This might be causing the error you're experiencing.

import json

response = client.send_message(
    ContentType='application/json',
    Content=json.dumps({'key': 'value'}),
    ConnectionToken=connection_token
)
AWS
David C
answered a year ago
  • Thanks for your quick answer, but sadly this was just a typo from copying over my code. An invalid JSON actually produces another error: An error occurred (InvalidRequestException) when calling the SendMessage operation: Message content is not a valid JSON.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions