Hi,
I have being using a JQL query for a long time, and suddenly stop working. I was in a middle of an internal migration (migrating servers in my organization), so I didn't use the query/script for about two weeks. Yesterday, when I run it, didn't work at all.
This is the script:
#!/bin/bash
for (( i=0; i<9000; i=i+100))
do
curl -u 'user@domaon:_token_that_works' -X POST -H "Content-Type: application/json" --data '{"jql":"order by updated asc","startAt":'$i',"maxResults":1000,"fields":["key","created","updated","summary","assignee","status","customfield_11400","project","reporter","customfield_10000"]}' https://mydomain.atlassian.net/rest/api/2/search | jq -r '.issues[]' --compact-output >> /some/path/jira.json
done
In the first part (curl), the only thing I get is:
{"startAt":0,"maxResults":100,"total":0,"issues":[]}
But If I go to the same URL (https://mydomain.atlassian.net/rest/api/2/search), with a regular browser, I see the tickets there...
Where is the problem?
Sacha
The answer is what Andrew says, but the key part is that when you encothe the string (email:token) has to be done like this:
$ echo -n email:token | base64
wothout the -n doesn't work.
Hi Sacha,
I understand that your script was making a REST API call to Jira Cloud and this recently stopped working.
This is because Atlassian's Cloud platform recently deprecated support for use of password and cookie based auth when using basic auth for REST API. Details in https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-user-privacy-api-migration-guide/
You can still use a REST API and your token to make rest calls, but you need to follow a few different steps aside from trying to use the -u username:passowrd_OR_token method.
Steps to do this are in: https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/
Supplying basic auth headers
If you need to, you may construct and send basic auth headers yourself. To do this you need to perform the following steps:
- Generate an API token for Jira using your Atlassian Account: https://id.atlassian.com/manage/api-tokens.
- Build a string of the form
useremail:api_token
.- BASE64 encode the string.
- Supply an
Authorization
header with contentBasic
followed by the encoded string. For example, the stringfred:fred
encodes toZnJlZDpmcmVk
in base64, so you would make the request as follows:Copycurl -D- \
-X GET \
-H "Authorization: Basic ZnJlZDpmcmVk" \
-H "Content-Type: application/json" \
Try these steps to create this new header instead, this should help you to allow this script to work again. Please let me know if you run into any problems.
Regards,
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andrew,
I took your bullet points and this is what I did:
Go it.
Un my case: info@akainix.com:iiFkR1(_some_other_chars_)MF0F2
I put that string (info@akainix.com:iiFkR1(_some_other_chars_)MF0F2) in a text file and “base64 it”: “cat file.txt | base64” and I got something like “aW5mb_56_chars_in_total_UYwRjIK”
In my case:
curl -X POST -H "Authorization: Basic aW5mb_56_chars_in_total_UYwRjIK" -H "Content-Type: application/json" --data '{"jql":"order by updated asc","startAt":'0',"maxResults":1000,"fields":["key","created","updated","summary","assignee","status","customfield_11400","project","reporter","customfield_10000"]}' https://akainix.atlassian.net/rest/api/2/search
The response:
Unauthorized (401)
My only guess, is that there is some error in the cat file.txt | base64 part.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also just create e new token, and tried with:
sacha@akainix.com:new_token
info@akainix.com:new_token
Then I transform it to base64... same result (401).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Finally it's working...
What I did before was:
$ echo email:token | base64
And I got something like:
c2FjaGFAYWthaW5peC5jb206bjZNNEhSM1locHVUQWwwUGRpaHpGRThGCg
But what I do now is:
$ echo -n email:token | base64
And I get something like:
c2FjaGFAYWthaW5peC5jb206bjZNNEhSM1locHVUQWwwUGRpaHpGRThG
The "-n" was the key...
After that, it is working fine. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.