How to send request body in post curl

I have written an API in java. Trying to hit using curl from the shell script.

local CONTENT_SOURCE="$1"
curl "$APP_URL/api/admin/sync" \ --header 'Content-Type: application/json' \ --data '{"content": "$CONTENT_SOURCE", "usernames": [""]}' \ -w "\n"

How to send CONTENT_SOURCE in the request body?

1 Answer

Build your JSON data with jq like this:

JSON_DATA=$(jq --null-input --arg content "${CONTENT_SOURCE}" '{"content": $content, "usernames": [""]}')

And use it with your cURL command:

curl "$APP_URL/api/admin/sync" \ --header 'Content-Type: application/json' \ --data "${JSON_DATA}" \ -w "\n"
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like