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...
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"