jira_tips
  • Article
  • Jan.19.2017

JIRA REST API – how it's done

  • Jan.19.2017
  • Reading time mins

As consultant, I usually use JIRA REST API to execute repetitive tasks like creating issues with attachments in bulk, or when developing add-ons for JIRA. I’ve also seen some of our clients use REST API to create a specific report or to sync JIRA issues with other systems. So let’s take brief look into JIRA REST API.

What exactly is REST API?

REST (Representational State Transfer) is an architectural style and approach to communications that is often used in the development of web services.

JIRA provides a wide range of REST API resources that helps developers create communication between JIRA and other applications. For example, Atlassian connect add-ons use REST API to communicate with JIRA. 

With these resources you can create, update, edit and delete data in JIRA using standard HTTP methods like GETPUTPOST and DELETE

Atlassian REST API Browser 

Atlassian REST API Browser provides a browser for available JIRA REST resources and some add-ons like JIRA Agile. After installing the add-on, go to Systems > Advanced Section > REST API Browserand you should see the below: 

API Browser

You will have to click on the Drop access link in the information message for the search APIs bar shown below to appear. 

search bar

{ “fields”: { “project”: { “id”: “10000” }, “summary”: “Summary of the issue created using REST API…”, “description”: “Issues description”, “issuetype”: { “id”: “3” } } }

Now let’s get started!

Firstly you will need to define the action you are trying to perform – for example create a ticket, attach a file, add a user or get the information of specific custom field.

For this tutorial we will try to create a ticket using REST. To get the correct API resource, you need to use either the API browser of the Atlassian Developer Toolbox add-on or Atlassian documentation JIRA REST API documentation.

Create API

As seen in the screenshot above when typing the word create, we automatically highlight the API to perform the action. On the right side you will see a brief description of the API, the parameter options and the HTTP method that should be used to perform the request successfully.

For this example, you don’t have to provide any parameters or the HTTP method you should use to create the issue is POST method. Now let’s build the body of the request using JSON format to create a ticket. I’ve already configured my JIRA instance as the following: 

Project/Custom field Name

Key/ID

Test Project

TP

REST API

10100

Sample of JSON request: 

{ “fields”: { “project”: { “key”: “TP” }, “summary”: “Summary of the issue created using REST API…”, “description”: “Description of the issue”, “issuetype”: { “id”: “3” }, “assignee”: { “name”: “admin” }, “reporter”: { “name”: “admin” }, “priority”: { “id”: “1” }, “customfield_10100”: “DATA INSERTED INTO REST API CUSTOM FIELD” } }

From the above JSON request, I’ve set the JIRA Project Key, Summary, Description, Issue Type, Assignee, Reporter, Priority and Custom Field (name: REST API).

Request Body

Write or copy the JSON example above into the Request Body of the browser and change the values like the ID of the issue type, Priority, Custom Field and Project key to you own JIRA instance values. Once it’s ready, click Send and you should see the response message as shown below: 

response

The response message should show the ID, key and full URL of the newly created ticket. You can use the URL to find the actual ticket in your project.

CF

Congratulations, you’ve successfully managed to create a ticket using JIRA REST API!

REST clients

Alternatively, you can use browsers’ rest clients extensions or add-ons to execute your operations. For example the Advanced Rest Client Chrome extension allows you to send custom requests from your browser to any application that supports REST

We will use the URL for the REST to create an issue from the previous example: 

http://localhost:8080/rest/api/2/issue

After installing the extension in Chrome, you should see the screenshot below: 

ARC

I’ve highlighted the different sections that we will use to create a ticket in JIRA.

Name Data

URL

http://localhost:8080/rest/api/2/issue

HTTP method

POST

Header

admin:admin

Request Body

{ “fields”: { “project”: { “key”: “TP” }, “summary”: “REST API TEST”, “description”: “Creating of a ticket using project keys and issue type names using the REST API”, “issuetype”: { “id”: “3” }, “assignee”: { “name”: “admin” }, “reporter”: { “name”: “admin” }, “priority”: { “id”: “1” }, “customfield_10100”: “DATA INSERTED INTO REST API CUSTOM FIELD” } }

The only difference between the previous example in Atlassian REST API Browser add-on and Advanced Rest Client is that the login is required in the header section, as shown in the table above (username:password). As we are creating the data from outside JIRA, you must provide a user that has create issue permission in JIRA(Note: the colon is required between username and password).

The final request should look like below : 

ChromeExRequest

After clicking on Send, the response message will appear: 

ChromeExResponse

What’s Next ? 

You’ve just seen one of the many REST API resources provided by JIRA and other Atlassian tools. The best place to find those resources and more examples on how to use them are in the links below :

Related resources

View all resources