Last updated Nov 14, 2024

Connect cookbook

This cookbook is an extension of the JavaScript API Cookbook, which provides snippets of code that can be used in the clients browser to get information from the product.

Forge is our recommended platform for building Atlassian cloud apps. See the cloud development platform overview for a comparison between Forge and Connect.

Access a list of Jira projects

Use this to retrieve a list of your Jira projects. Depending on your projects, you might need to paginate to see complete results. You can do this by passing startAt in the request query string.

The AP object is the JavaScript API provided to Connect apps loaded inside an iframe. You can view a full list of the available API methods in the Connect JavaScript API docs

1
2
AP.request({
  url: '/rest/api/latest/project',
  success: function(response) {
    // convert the string response to JSON
    response = JSON.parse(response);

    // dump out the response to the console
    console.log(response);
  },
  error: function() {
    console.log(arguments);
  }  
});

Search for an issue using JQL

In this example you'll create a simple JQL (Jira query language) query that looks for unresolved issues (resolution = null). The JQL query is in the searchJql parameter of the request. You might need to paginate your results to get through all of them.

1
2
var searchJql = 'resolution = null';

AP.request({
  url: '/rest/api/latest/search?jql=' + encodeURIComponent(searchJql),
  success: function(response) {
    // convert the string response to JSON
    response = JSON.parse(response);

    // dump out the response to the console
    console.log(response);
  },
  error: function() {
    console.log(arguments);
  }    
});

Create a Jira issue

This recipe creates a new issue for an existing Jira project. Depending on how your project is configured, you might need to include additional fields. See Create issue in the REST API documentation for details.

1
2
var issueData = {
  "fields": {
    "project": { 
      "key": "TEST"
    },
    "summary": "REST ye merry gentlemen.",
    "description": "Creating of an issue using project keys and issue type names using the REST API",
    "issuetype": {
      "name": "Task"
    }
  }
};

AP.request({
  url: '/rest/api/latest/issue',
  // adjust to a POST instead of a GET
  type: 'POST',
  data: JSON.stringify(issueData),
  success: function(response) {
    // convert the string response to JSON
    response = JSON.parse(response);

    // dump out the response to the console
    console.log(response);
  },
  error: function() {
    console.log(arguments);
  },
  // inform the server what type of data is in the body of the HTTP POST
  contentType: "application/json"    
});

Rate this page: