Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Why my JQL stop working?

Sacha Yunusic July 9, 2019

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

2 answers

2 accepted

0 votes
Answer accepted
Sacha Yunusic July 11, 2019

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.

0 votes
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 10, 2019

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:

  1. Generate an API token for Jira using your Atlassian Account: https://id.atlassian.com/manage/api-tokens.
  2. Build a string of the form useremail:api_token.
  3. BASE64 encode the string.
  4. Supply an Authorization header with content Basic followed by the encoded string. For example, the string fred:fred encodes to ZnJlZDpmcmVk in base64, so you would make the request as follows:
Copy
curl -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

Sacha Yunusic July 10, 2019

 

Hi Andrew,

 

I took your bullet points and this is what I did:

 

Go it.

  • Build a string of the form useremail:api_token.

Un my case: info@akainix.com:iiFkR1(_some_other_chars_)MF0F2

  • BASE64 encode the string

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”

  • Supply an Authorization header with content Basic followed by the encoded string. For example, the string fred:fred encodes to ZnJlZDpmcmVk in base64, so you would make the request as follows

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.

Sacha Yunusic July 10, 2019

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).

Sacha Yunusic July 11, 2019

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. :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events