Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I can get JSON results from the browser but not through scripting?

Hi,

I'm trying to get worklogs using REST API and I'm able to get results but when I use the same call using javascript (Google Spreadsheet scripting) despite providing user login credentials, I get a 403 instead. Is there a setting in JIRA that I need to turn on to allow me to get same results?

Thanks,

Jeff

1 answer

No, there's nothing to change - you get a 403 because your code is not passing the right credentials and/or a valid REST call.  We can't tell you what is wrong with your REST call without seeing it.

Thanks for the reply Nick, but I'm pretty sure I given the correct credentials. The rest call works on the browser and it work on a client JIRA cloud instance. Below is the code I use on Google Spreadsheet:

 var url = "https://jira.my-domain.com/rest/api/2/mypermissions";
var x = Utilities.base64Encode("jeferson:password");
// I also tried the token generated from https://id.atlassian.com/manage/api-tokens

var headers = {
"Accept":"application/json",
"Content-Type":"application/json",
"method": "GET",
"headers": {"Authorization": "Basic " + x},
"muteHttpExceptions": true
};

var response = UrlFetchApp.fetch(url, headers); // gets a 403
var errormsg = response.getResponseCode();
var dataAll = JSON.parse(response.getContentText());
var dataSet = dataAll;

There is nothing to configure in a Jira server instance to "enable" anything.  The 403 happens because your credentials for what you're asking are not valid for the system. 

Sometimes, this is when you try to do something that you don't have permissions for, and sometimes, it's a network gateway/proxy/firewall that doesn't like the credentials.  But mostly, it's going to be because your credentials are invalid.

Okay, thanks for replying but this still does not answer why I can get results if I access the URL straight from the browser and fails if it's from the script. I'm using the same credentials so this should not be a permission issue.

The only thing I'm thinking right now is that CAPTCHA might be triggering (I just noticed now that after the an update, my login from time to time triggers a CAPTCHA). I will ask are IT team to check if we can temporarily disable this for my user just to test if the script would work.

All I can tell you is that there is something wrong in the script - it's not passing Jira a valid set of credentials.

But I think your Captcha instinct is almost certainly spot-on - once you've failed login a few times, you'll need to pass that test to allow login.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,894 views 11 5
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you