1

I faced with problem when created simple bash script, so, my goal - fect jwt token and will use tokn in next query, For that first curl fetch credentials from login.json file and then set it in result.json, then reed token key and set it in variable tokenValue then I want to set it on bext curl in header but when I debugged I did not get Authorization header, why ? When I substitute the variable manually (like "Authorization: Bearer test_token") - it's worked, I faced with HTTP_AUTHORIZATION=Bearer test_token

curl --request POST -sL \
     --url 'http://auth.loc/api/login'\
     --output './result.json' \
     --header "Content-Type: application/json" \
     -d "@login.json" \

tokenValue=$(jq -r '.token' './result.json')
bearerToken="Authorization: Bearer "$tokenValue
echo 'fff' + $bearerToken

curl --request GET -sL \
     --url 'http://qbee.local/api/v2/grouptree?_format=json'\
     --output './grouptree_result.json' \
     --header $bearerToken \

echo "$(cat grouptree_result.json)"

echo 'fff' + $bearerToken works fine, I faced with correct data in cli

1
  • Make sur you don't get a CR in $bearerToken. On another note, maybe you should also add a Content-Type header. Commented May 18, 2021 at 9:26

1 Answer 1

2

I found out how to resolve it. Problem was with double and single quotes

curl --request POST -sL \
 --url 'http://qbee.local/api/v2/login'\
 --output './result.json' \
 --header "Content-Type: application/json" \
 -d "@login.json" \

tokenValue=$(jq -r '.token' './result.json')

echo 'token was' + $tokenValue

curl --request GET -sL \
     --url 'http://qbee.local/api/v2/metric/1587260952123_10?type=group'\
     --output './metric_result.csv' \
     --header 'Authorization: Bearer '"$tokenValue" \
     --header 'Content-Type: csv' \

echo "$(cat grouptree_result.json)"
Sign up to request clarification or add additional context in comments.

1 Comment

--header "Authorization: Bearer $tokenValue"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.