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