1

I am trying to use a variable in the header of a curl command, can anyone please help in finding the solution?

curl --location \
  --request POST https://abc/bcd \
  --header 'Content-Type: application/json' \
  --header 'id: $empid' \
  --data-raw '{
                    "clientName": "name",
                    "role": "dev",
                    "group": "groupid"
                    }'

Here I am trying to get the empid value in the header section, but I am not getting the value instead getting the same variable $empid.

Thanks in advance.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74

1 Answers1

2

Rewrite you script as follow:

curl --location \
  --request POST https://abc/bcd \
  --header "Content-Type: application/json" \
  --header "id: $empid" \
  --data-raw "{
                    \"clientName\": \"name\",
                    \"role\": \"dev\",
                    \"group\": \"groupid\"
                    }"

If you need variable sostitution you have to use double quotes instead of single quotes.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74