I want to have a curl command like below
curl --location --request POST 'https://abcd.com/api/v4/projects/<projectId>/triggers' \
--header 'PRIVATE-TOKEN: <your_access_token>' \
--form 'description="my description"'
Now I wrote a shell script function to generate it dynamically
it need projectId, token, and description as a pramter
callApi(){
while IFS="," read -r -a users; do
for u in "${users[@]}"
do
url="'https://abcd.com/api/v4/projects/$1/triggers'"
echo $url
header="'PRIVATE-TOKEN: $2'"
echo $header
desc="'description=$u token'"
echo $desc
tk=$(curl --location --request POST $url
--header $header
--form $desc)
echo $tk
done
done <<< $(cat $3)
}
callApi "<projectId>" "<token>" ./users.csv
It echo perfectly But It thorws error
https://www.shellcheck.net
. Basically, remove your single quotes to allow variable expansion and place your options into an arrayurl=("https://abcd.com/api/v4/projects/$1/triggers")
– rr0ss0rr Mar 16 '22 at 17:06POST "$url" --header "$header" --form "$desc"
. – G-Man Says 'Reinstate Monica' Mar 16 '22 at 17:16