Curl command to output only the token so that I could pass it to another command. I am running the command below:
curl --location --request POST 'https://xxx.xxx/authtoken' \
--header 'authString: OEU4MkVDRjctMERDNy0yRDlBLTYxNzZFOUFFMjI0OEMyRkI6NTU1QjVEOUItOTRGOS00MkM2LUJDRUFEQjE4MUU1MzhBMUU=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cookie: CFID=xxxx; CFTOKEN=xxxxxx; APITOKEN=xxxxxx; JSESSIONID=xxxxxxxxxx' \
--data-urlencode 'authString=xxxx-xxxx-xxxxx-xxxx=='
The output is shown as per below:
{"message":"","success":true,"timestamp":"August, 04 2022 10:20:23","apiToken":"321D8093-0014-ED11-9105-0050568D5083"}
What I really need is to be able to save the apitoken so that I could save it as an environmental variable for the next curl command
I am sure that it can be done with grep but I haven't been able to get the string that I need.
CodePudding user response:
Your shown output:
$ cat file
{"message":"","success":true,"timestamp":"August, 04 2022 10:20:23","apiToken":"321D8093-0014-ED11-9105-0050568D5083"}
is JSON so use jq
to parse it, not grep
.
Replace cat file
with curl ...whatever...
:
$ var=$(cat file | jq -r '.["apiToken"]')
$ echo "$var"
321D8093-0014-ED11-9105-0050568D5083