Forums

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

Error while accessing REST API

Ravishankara Shastry June 25, 2019

I am trying to use REST API from a perl script. I am able to login with my credentials directly to the Jira, but getting error 501 when tried with REST API.

URL used is: https://mycompany.atlassian.net/rest/api/2/

Is there anything like REST API access has to be enabled explicitly for a particular user from the administrator? If so, how can it be done?

2 answers

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2019

Hello,

You are making request to Cloud but you are using rest api for server. Moreover https://mycompany.atlassian.net/rest/api/2/ has no sense. There must something after like https://mycompany.atlassian.net/rest/api/3/project

Ravishankara Shastry July 16, 2019

I used https://mycompany.atlassian.net/rest/api/3/ to access Jira via a script.

my $serverurl = "https://mycompany.net/rest/api/3/";
my $username = 'my.email@domain.com';
my $password = 'my_API_token';

my $headers = {Accept => 'application/json', Authorization => 'Basic ' . encode_base64($username . ':' . $password)};

my $client = REST::Client->new();
if (!$idartinstance)
{
print " Trying to Connect to JIRA using REST client interface \n\n";

$client->GET($serverurl."serverInfo", $headers);
print $client->responseCode();
$idartinstance = decode_json($client->responseContent());
}

With this, I am getting following error:

malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "LWP will support htt...") and the response code is 501.

 

Could someone point where/what is wrong here?

0 votes
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2019

If you were using basic authentication method in your script then you should change it to either oauth or token, since Atlassian have deprecated and started to disable basic auth for security reasons:

https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/

Suggest an answer

Log in or Sign up to answer