API Tokens for self-hosted Jira

sqlsith
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 13, 2018

Hello! We host our own Jira instance and I can't figure out how to create API tokens that will work on it. I do not want instructions on how to make API tokens for the cloud - that is easy to find - but specifically for our own hosted instance. Is this documented online?

Thanks,
Chris

3 answers

1 accepted

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

Hi everyone,

For Jira Server users that want to create a REST API token, I would actually recommend checking out the Jira Server Devleoper page on OAuth.  This is the recommended method for authenticating REST requests against Jira.  It tends to be considerably more complicated to setup and configure than other methods like basic auth, but it is much more secure of a method for making REST requests.

Regards,

Andy

Prabu Sivagnanam June 4, 2019

I'm salesforce resource.....How to get API Token from JIRA Server (Note:Not for Jira cloud), Actually i am trying to push some records from Salesforce to JIRA..So i need it

 

Previously in my another POC i was able to connect from SFDC to JIRA cloud by the API token from JIRA cloud (profile --> Manage your Account-->Security-->API token-->Create and manage API tokens--> Manage your account-->API tokens)

 

But in JIRA Server instance dont know from where to get API Token

 

Regards,

Prabu

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 5, 2019

Hi Prabu,

Jira Server does not provide those specific types of API tokens that can be used in basic auth, like Jira Cloud does.   If you want to create a token in Jira Server for use in REST calls, you need to create an OAuth token, which has an expectation of creating an application link as described in Jira Server Devleoper page on OAuth.

It is more setup and configuration for the use of a token in this case, but it a more secure method than basic auth is.

If you don't need this level of security, then you could follow the Jira Server basic auth steps in https://developer.atlassian.com/server/jira/platform/basic-authentication/

This page has steps where you can encode a sting of username:password and include that in an authorization header as a means to authenticate.  It's not nearly as secure as an OAuth token would be, but it is considerably easier to setup.

I hope this helps to clarify the confusion between platforms.

Andy

Like # people like this
Prabu Sivagnanam June 5, 2019

Thank you so much @Andy Heinzer  !  Just now i have did code(in Salesforce  for connecting with JIRA using Basic Authentication.

-------------------------------------------------------------------------------------------------

I able to connect with the app which is hosted on web server which having internet address.

HTTP h = new HTTP();

HTTPRequest r = new HTTPRequest();

r.setEndpoint('https://workflowtest.ghx.com/rest/api/2/issue/createmeta');
Blob headerValue = Blob.valueOf('Uname' + ':' + 'Pwd');

String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
System.debug('authorizationHeader : '+authorizationHeader );
r.setHeader('Authorization', authorizationHeader);
r.setMethod('GET');
HTTPResponse resp = h.send(r);

 

Output : I able to connect with the JIRA server hosted on Web  - workflowtest.ghx.com

-----------------------------------------------------------------------------------------------

But unable to connect with my localhost:2990(actually my business asked me to do POC in the local)

HTTP h = new HTTP();

HTTPRequest r = new HTTPRequest();
//http://localhost:2990/jira/rest/api/2/issue/TP-7
r.setEndpoint('http://192.168.3.43:2990/jira/rest/api/2/issue/TP-7');
//r.setEndpoint('http://localhost:2990/jira/plugins/servlet/restbrowser#/');
Blob headerValue = Blob.valueOf('admin' + ':' + 'admin');

String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
System.debug('authorizationHeader : '+authorizationHeader );
r.setHeader('Authorization', authorizationHeader);
r.setMethod('GET');
HTTPResponse resp = h.send(r);

I told the business as below

 

Output: I tried many combination here  by changing URI of the Localhost URI many ways but always getting [Status=Forbidden, StatusCode=403], So it seems i cant connect with localhost from salesforce since salesforce can't resolve the URL in Local host

************************************

FYI I able to connect with workflowtest.ghx.com(Jira Server version) with Basic Authorization from salesforce (instead of OAuth which i used previously connecting to Jira cloud from Salesforce)....I trying to replicate the same Basic Authorization with Jira which running in my localhost,

From Salesforce we can't connect with application which is hosted in localhost ,Salesforce can connect with the applications only hosted on internet web server...So Can I use workflowtest.ghx.com for POC purpose ?

But business replied as below

**********************************

sorry, dont want to POC work in workflowtest.ghx.com(Jira Server version) 

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 7, 2019

Hi Prabu,

It looks like you're using the SDK here.  When running that atlas-run SDK command, it will default to having the servername be localhost.  But this is something you can change when starting the SDK.  Please see the https://developer.atlassian.com/server/framework/atlassian-sdk/atlas-run/

Specifically you will want to use the --server parameter in order to set a host/address that this Jira SDK instance can be reached on.  For example:

atlas-run --product jira --server hostname.example.com

Granted you might need to then also make sure that your have a DNS record that resolves that hostname to the address you want to connect on, but I think this will be needed since you don't really want to be running this on localhost here.

If you don't specify that --server tag on the startup of the SDK here, it will default to localhost.  At which point you might still be able to access the Jira site on your 192.168.x.x address, but you could then also be running into CORS or XSRF protections in Jira that prevent you from trying to make REST API calls to addresses that Jira isn't actually intended to be listening to requests from.

I hope this helps.

Andy

4 votes
Franco Allen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 1, 2019

Hi Chris,

 

No it's not documented because haven't developed yet by Atlassian (here is a ticket JRASERVER-67869)

API Tokens for Jira this is exactly what are you looking for

Also seems that it is much easier to use than OAuth

 

Cheers, Franco

Jaylynn Soto October 2, 2019

Thanks Franco!

Christian Reichert _resolution_
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.
December 10, 2019

Hi!

There's also an App from our side which does this: https://marketplace.atlassian.com/apps/1221586/api-token-authentication-for-jira?hosting=server&tab=overview

Today both apps are similar but do differ in the feature set slightly. 

Cheers,
Chris

P.S. Full disclosure, I work for resolution, a marketplace vendor.

Like Jaylynn Soto likes this
Jaylynn Soto January 10, 2020

Thank you, Chris

1 vote
Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 13, 2018

@sqlsithSee here,  this you need Oauth-Access Token

 

Best!

sqlsith
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 14, 2018

Thanks Moses!

Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 15, 2018

@sqlsithYou are welcome!

 

Best!

Suggest an answer

Log in or Sign up to answer