Jira Align API call fails with a 401 error when running in curl
Summary
A Jira Align REST API call, made using the curl application, fails reporting a 401 error
While this issue was initially identified as reporting a 401 error when run on a Linux client , the exact error appears to depend on the operating system or version of curl running on the client, as testing on a Mac, using curl, returned an "Event not found" message in place of a 401 error.
Environment
Jira Align
Diagnosis
- The bearer token being used for authentication was confirmed as valid
- Using the browser based Swagger page instead of curl was successful in making the same API call
- This success was seen when using the same bearer token for authentication and on a client system running in the same subnet as the one that reported the error
Cause
The issue was caused by the format of the curl command. The failing command had been entered using double quotes around Authorization parameter of the command as shown in the example below
curl -v -X GET "https://YYYYYYY.jiraalign.com/rest/align/api/2/Users/whoami" -H 'accept: application/json;odata.metadata=minimal;odata.streaming=true' -H "Authorization: bearer user:nnnn|abcdefgh`ijk"
Solution
Make sure that the parameters specified in the API call are surrounded by single quotes as indicated in the below below:
curl -v -X GET "https://YYYYYYY.jiraalign.com/rest/align/api/2/Users/whoami" -H 'accept: application/json;odata.metadata=minimal;odata.streaming=true' -H 'Authorization: bearer user:nnnn|abcdefgh`ijk'
From testing on a Mac client, It appears that the endpoint URL itself can be surrounded by either double quotes or single quotes for the command to run successfully