Skip to content

INTEGRATION ·

Salesforce – Jira Cloud Integration

The configuration settings needed to integrate Salesforce with Jira Cloud by consuming the Jira REST APIs: an Atlassian OAuth 2.0 app, an Auth. Provider and a Named Credential.

This article lists the configuration settings needed to integrate Salesforce with Jira Cloud by consuming the Jira REST APIs.

Key steps

  1. Create an integration app in Jira that provides the API credentials for Atlassian products and services, and features such as OAuth 2.0 (3LO) on the Jira platform, through the Atlassian Developer Console.
  2. Create an Auth. Provider of type “Open ID Connect” in Salesforce, so your Salesforce instance can access protected third-party data on behalf of users.
  3. Create a Named Credential that specifies the URL of the callout endpoint and its authentication parameters (the Auth. Provider) in one definition.

1. Create an OAuth 2.0 integration app in the Atlassian Developer Console

This app connects to the Jira platform (Atlassian products and services). Under “Create app”, click “OAuth 2.0 (3LO) integration”.

Atlassian Developer Console: My apps, Create app menu

Enter a name for the app and click Create.

Creating a new OAuth 2.0 (3LO) integration

On the Permissions tab, configure the app's API scope for the Jira platform REST API (get, create, update and delete issues, projects, fields and more).

Permissions tab listing the available APIs

Add all the APIs to the scope.

Jira platform REST API scopes added

2. Create the Auth. Provider in Salesforce

Your Auth. Provider settings in Salesforce will look much like this:

Salesforce Auth. Provider detail for Jira
  • Consumer Key: in the Atlassian Jira app, go to Settings, copy the Client ID and paste it.
  • Consumer Secret: in the Atlassian Jira app, go to Settings, copy the Secret and paste it.
  • Authorize Endpoint URL: https://auth.atlassian.com/authorize?audience=api.atlassian.com
  • Token Endpoint URL: https://auth.atlassian.com/oauth/token
  • Default scopes: read:jira-work manage:jira-project manage:jira-configuration read:jira-user write:jira-work manage:jira-data-provider offline_access

Click Save. Salesforce then generates some configuration URLs: note the Callback URL. In Jira, go to Authorization, click Configure and paste in the Callback URL. Atlassian: OAuth 2.0 (3LO) apps

Jira app Authorization: OAuth 2.0 authorization code grants callback URL

3. Create the Named Credential

  • URL: https://{your-org-jira-instance}.atlassian.net
  • Authentication Provider: the Auth. Provider created earlier. Leave Scope empty so the default scope of the Auth. Provider is used.
  • Tick “Generate Authorization Header”.
Salesforce Named Credential JiraOAuth using the Jira Auth. Provider

Jira REST APIs for common operations (version 2, stable)

POST   /rest/api/2/issue                      # create issue
GET    /rest/api/2/issue/{issueIdOrKey}       # get issue
DELETE /rest/api/2/issue/{issueIdOrKey}       # delete issue
PUT    /rest/api/2/issue/{issueIdOrKey}       # update issue
POST   /rest/api/2/project                    # create project
GET    /rest/api/2/project/{projectIdOrKey}   # get project
DELETE /rest/api/2/project/{projectIdOrKey}   # delete project
PUT    /rest/api/2/project/{projectIdOrKey}   # update project

The full reference is in the Jira REST API documentation. Jira REST API reference

4. Call Jira from Apex

Finally, create an Apex class and methods that make callouts to the Jira platform using the Named Credential created above.

public class JIRAClass {

    public static String baseUrl = 'callout:JiraOAuth/rest/api/2/issue';

    // Sends a request and returns the response
    public static HttpResponse sendRequest(HttpRequest req) {
        Http http = new Http();
        return http.send(req);
    }
}
@future (callout=true) WebService static void createIssue(String baseUrl, String projectKey, String issueTypeName,
                                                          String issueDescription) {
    try {
        HttpRequest req = buildRequest(baseUrl, projectKey, issueTypeName, issueDescription);
        HttpResponse res = JIRAClass.sendRequest(req);
        System.debug(res.getBody());
    } catch (System.CalloutException e) {
        System.debug('cause' + e.getCause() + 'message : ' + e.getMessage() + 'typeName :' + e.getTypeName());
    }
}

For more on making callouts with Named Credentials, see the Salesforce documentation. Salesforce: Named Credentials as callout endpoints

First published on 14 March 2021 by GeekSoft Consulting.

CONNECTED TECHNOLOGY. HUMAN IMPACT.

Let's build what's next.

Let's talk.

Tell us what you are working on and we will get back to you as soon as possible.