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={
"id": "f23399af-a384-4ed3-bac0-386a01804d83",
"de": {
"price": 10.59
},
"nl": {
"price": 107.99
},
"pl": {
"price": 12.15
}
}'
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&[email protected]
What I already tried
curl --request POST -data-urlencode http://localhost:9324/queue/price-import?Action=SendMessage&[email protected]
curl --request POST -data-urlencode input.json http://localhost:9324/queue/price-import
curl --request POST -data-urlencode "[email protected]" http://localhost:9324/queue/price-import
curl --request POST --data-urlencode [email protected] --url http://localhost:9324/queue/price-import?Action=SendMessage
Resources I found
- Unix cURL POST to specific variable using contents from a file
- POSTing a file's contents with CURL
- curl.1 the man page
CodePudding user response:
Answering to my own question based on this answer:
How to urlencode data for curl command?
This worked for me:
curl \
--data-urlencode [email protected] \
--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
}
}