0

I'm trying to send a message to an SQS queue. I have everything setup correctly. I'm using a fifo queue, so my post string looks like this:

https://queuename?Action=SendMessage&MessageBody=TEST&MessageGroupId=6&MessageDeduplicationId=6

The above works and the body of the message is TEST, However, I'd like to send data in JSON format In the body tab, I have my payload formatted in JSON. How do I get that JSON value into the MessageBody field as a variable?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
stormyguy
  • 60
  • 7

1 Answers1

1

Step 1. Save json in a variable

const body = {
    "key": "value"
}

//encoded the special character to make it valid in URL
const payload = encodeURIComponent(JSON.stringify(body))

//Put it in an environment variable
pm.environment.set("payload", payload)

Step 2: Use this var in URL

https://queuename?Action=SendMessage&MessageBody={{payload}}&MessageGroupId=6&MessageDeduplicationId=6
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
  • Thank you very much. This worked. I think I was missing the encoding line. Now, on the same topic of sending JSON data, it appears you can also send Message Attributes which is also in JSON... so how would I send message attributes in addition to message body [link]https://docs.aws.amazon.com/cli/latest/reference/sqs/send-message.html – stormyguy Apr 02 '22 at 22:50
  • This docs for AWS CLI, not for HTTP client. You have to know how CLI convert this to HTTP request then put it in Postman. My recommend is use a proxy to capture all request from AWS CLI, then you will know how this CLI construct the message request. My experience of AWS is zero, I can't help you. – lucas-nguyen-17 Apr 03 '22 at 00:37