i'm looking to integrate jira to my project for i have implemented OAuth 2.0 (3LO).

Gourav Puri Goswami
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!
January 2, 2025

 

I’m facing an issue with the accessible-resources API. It returns multiple cloud IDs, and I’m unsure which one to use. Additionally, I’m receiving account details for accounts that I didn’t select on the consent screen.

If resolving this isn’t possible, is there an alternative? My goal is to access issue types and projects from a Jira account to raise Jira tickets, as well as create and manage projects and issue types—all while using a bearer token for authentication. However, since the APIs primarily rely on basic authentication, how can I proceed using only a bearer token?

Any guidance or suggestions would be greatly appreciated!

here is the curl for creating isssue with api token but ineed to find out way to do itusng bearer token


curl --request POST \ --url 'https://your-domain.atlassian.net/rest/api/3/issue' \ --user 'email@example.com:<api_token>' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "fields": { "assignee": { "id": "5b109f2e9729b51b54dc274d" }, "components": [ { "id": "10000" } ], "customfield_10000": "09/Jun/19", "customfield_20000": "06/Jul/19 3:25 PM", "customfield_30000": [ "10000", "10002" ], "customfield_40000": { "content": [ { "content": [ { "text": "Occurs on all orders", "type": "text" } ], "type": "paragraph" } ], "type": "doc", "version": 1 }, "customfield_50000": { "content": [ { "content": [ { "text": "Could impact day-to-day work.", "type": "text" } ], "type": "paragraph" } ], "type": "doc", "version": 1 }, "customfield_60000": "jira-software-users", "customfield_70000": [ "jira-administrators", "jira-software-users" ], "customfield_80000": { "value": "red" }, "description": { "content": [ { "content": [ { "text": "Order entry fails when selecting supplier.", "type": "text" } ], "type": "paragraph" } ], "type": "doc", "version": 1 }, "duedate": "2019-05-11", "environment": { "content": [ { "content": [ { "text": "UAT", "type": "text" } ], "type": "paragraph" } ], "type": "doc", "version": 1 }, "fixVersions": [ { "id": "10001" } ], "issuetype": { "id": "10000" }, "labels": [ "bugfix", "blitz_test" ], "parent": { "key": "PROJ-123" }, "priority": { "id": "20000" }, "project": { "id": "10000" }, "reporter": { "id": "5b10a2844c20165700ede21g" }, "security": { "id": "10000" }, "summary": "Main order flow broken", "timetracking": { "originalEstimate": "10", "remainingEstimate": "5" }, "versions": [ { "id": "10000" } ] }, "update": {} }'

1 answer

1 vote
Humashankar VJ
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.
January 2, 2025

Hi @Gourav Puri Goswami 

While Jira's REST API does not directly support bearer token authentication for most operations, there are alternative approaches to consider.

  • One recommended method is implementing OAuth 2.0 with the authorization code grant type, which provides a bearer token for authentication.
  • This approach is endorsed by Atlassian for third-party integrations and offers improved security.
  • Other options include using Personal Access Tokens (PAT) or API tokens for basic authentication, which provide better security than using your actual password.

Besides that, if you're developing a Connect app, you can utilize the JWT bearer token authorization grant type (2LOi) to perform actions on behalf of users.

Hope this helps - Happy to help further!!
Thank you very much and have a great one!
Warm regards

Gourav Puri Goswami
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!
January 2, 2025

Thanks @Humashankar VJ ,

I'm using Oauth 2.0 with grant type as you have mentioned and getting access token as well. Now i'm looking to access jira apis using this access_token. What should be my approach to proceed further. I have also tried to use 'ex/jira' apis. As my goal is to mange jira projects and issues along side creating jira tickets through my application. Could you guide me implementing this effectively

Like Humashankar VJ likes this
Humashankar VJ
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.
January 2, 2025

Hi @Gourav Puri Goswami 

Verify that your access token has the necessary scopes, such as read:jira-work and write:jira-work, by checking the Atlassian Developer Console under your app's permissions.

  • Next, retrieve your Jira cloud ID by making a GET request to the accessible-resources endpoint, including your access token in the Authorization header.
  • With your cloud ID, construct the API endpoints using the format, and replace {cloudId} and {resource} with your specific values.

For example, to create an issue, use the POST endpoint. When making API calls, include your access token in the Authorization header and provide necessary data in the request body for POST requests.

In addition, implement a token refresh mechanism using the refresh token to handle token expiration, and utilize the refresh endpoint to obtain a new access token.

Regards

Gourav Puri Goswami
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!
January 2, 2025

@Humashankar VJ

I'm getting multiple cloud id's when getting available-resources which one to use there.


For ex:  At the consent screen i have selected site1 then too all resources are comming up how to resolve this. 

[

  {

    "id": "8594f221-9797-5f78-1fa4-485e198d7cd0",

    "name": "Site name 2",

    "url": "https://your-domain2.atlassian.net",

    "scopes": [

      "write:jira-work",

      "read:jira-user" ],

    "avatarUrl": "https:\/\/site-admin-avatar-cdn.prod.public.atl-paas.net\/avatars\/240\/koala.png"

  },

  {

    "id": "1324a887-45db-1bf4-1e99-ef0ff456d421",

    "name": "Site name 1",

    "url": "https://your-domain1.atlassian.net",

    "scopes": [

      "write:jira-work",

      "read:jira-user",

      "manage:jira-configuration" ],

    "avatarUrl": "https:\/\/site-admin-avatar-cdn.prod.public.atl-paas.net\/avatars\/240\/flag.png"

  }

]

 

Humashankar VJ
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.
January 2, 2025

Hi @Gourav Puri Goswami - You aware of the Jira instance URL you want to work with isn't it ?  match it against the "url" field in the response. Use the corresponding "id" for that URL.

Regards

Gourav Puri Goswami
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!
January 2, 2025

@Humashankar VJ , Indeed i'm aware of my jira instance. But the issue is that how manage it for my project as there can be many users that will be using it how would i be aware of there instances. I need to figure out for that. I have multiple instance for my jira account similarly others also may have. Is there any way to figure out which instance was selected on consent screen while outh authentication. As i dont want the user to select between instances each time. 

Humashankar VJ
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.
January 2, 2025

Hi @Gourav Puri Goswami 

Thanks for the additional note - there is no direct method to identify the chosen site from the consent screen.

Regards

Gourav Puri Goswami
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!
January 2, 2025

Thanks @Humashankar VJ , that's really helpful and prompt useful suggestions. Really appreciate it.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events