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

API Tokens for self-hosted Jira

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 Apr 05, 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

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 Jun 05, 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 Prabu Sivagnanam likes this

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 Jun 07, 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

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

Thanks Franco!

@Chris LeonardSee here,  this you need Oauth-Access Token

 

Best!

@Chris LeonardYou are welcome!

 

Best!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Jira Cloud for Google Sheets: Automatically Refresh Your Data!

Remember that time you realized it was possible to refresh your Jira data in Google sheets with just one click? What if we told you that you can now get the latest data with no clicks at all?! Zero! ...

7,364 views 33 29
Read article

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