0

Curl - Encode file as url query

I'm trying to send message to Amazon SQS queue with payload read from file using curl

So far I've got working curl to send message to queue but with harcoded value like:

curl --request POST \
     --url 'http://localhost:9324/queue/price-import?Action=SendMessage&MessageBody=%7B%0A%09%22id%22%3A%20%22f23399af-a384-4ed3-bac0-386a01804d83%22%2C%0A%09%22de%22%3A%20%7B%0A%09%09%22price%22%3A%2010.59%0A%09%7D%2C%0A%09%22nl%22%3A%20%7B%0A%09%09%22price%22%3A%20107.99%0A%09%7D%2C%0A%09%22pl%22%3A%20%7B%0A%09%09%22price%22%3A%2012.15%0A%09%7D%0A%7D'

And payload I send is:

{
    "id": "f23399af-a384-4ed3-bac0-386a01804d83",
    "de": {
        "price": 10.59
    },
    "nl": {
        "price": 107.99
    },
    "pl": {
        "price": 12.15
    }
}

How can I modify this curl to omit harcoded value and instead put path to file with .json extension?

Desired output

curl --request POST \
     --data-urlencode http://localhost:9324/queue/price-import?Action=SendMessage&MessageBody=@input.json

What I already tried

  • curl --request POST -data-urlencode http://localhost:9324/queue/price-import?Action=SendMessage&MessageBody=@input.json
  • curl --request POST -data-urlencode input.json http://localhost:9324/queue/price-import
  • curl --request POST -data-urlencode "sendbody@input.json" http://localhost:9324/queue/price-import
  • curl --request POST --data-urlencode SendBody@input.json --url http://localhost:9324/queue/price-import?Action=SendMessage

Resources I found

mikolaj semeniuk
  • 2,030
  • 15
  • 31

1 Answers1

0

Answering to my own question based on this answer:

How to urlencode data for curl command?

This worked for me:

curl \
    --data-urlencode MessageBody@input.json \
    --data-urlencode "Action=SendMessage" \
    http://localhost:9324/queue/price-import

and my input.json file:

{
    "id": "f23399af-a384-4ed3-bac0-386a01804d83",
    "de": {
        "price": 10.59
    },
    "nl": {
        "price": 107.99
    },
    "pl": {
        "price": 12.15
    }
}
mikolaj semeniuk
  • 2,030
  • 15
  • 31