Search code examples
amazon-web-servicesamazon-sqsaws-sqs-fifo

How to add JSON from "Body" in the query parameter?


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?


Solution

  • 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