Haut de page

Jira Cloud REST API: An easy overview


Posted by
Marcus Hilliges

April 24, 2018

Up until recently, the Jira REST API has been exclusive to server users and developers, but now Atlassian has released support for the Jira Cloud REST API, giving Cloud users the ability to harness the power of REST API calls in Jira environments.

What is a REST API?

Not too long ago, we wrote about Jira Server’s REST API, which is a method of allowing communication between a web-based client and server that uses representational state transfer (REST) constraints. It’s an architectural style that is used to communicate directly with applications through HTTP requests like GET, POST, PUT and DELETE to create, update, edit and delete data. When used in conjunction with Atlassian products, it is a fast and scaleable way of creating issues, setting permissions and performing JQL queries.

Limitations compared to server

In terms of functionality and the different calls you can make, there are no major differences between Jira Server and the Jira Cloud REST API. However, there are a few differences to keep in mind:

Can I get a Jira Cloud REST API example?

Of course!

We are going to use a REST API client to make our REST API call. For the examples in this article, we are going to use Postman which is a renowned API development solution. We won’t go deep into how to set it up, rather we’ll discuss how to make out first REST API call. Let’s start by having a look at the available calls that could be made from the documentation.

For this example, we are going to add a comment to an existing issue. The first thing we need to do is to add a collection in Postman. A collection essentially is a group of requests that can be executed over a loop of input parameters. Click New in the top left corner to create a collection; then create New again to create our first request.

Adding a comment means adding new data, which means the request type needs to be set to POST. The request we are going to use is /rest/api/2/issue/{issueIdOrKey}/comment. Set the request url to your Jira site url and replace the tag {issueIdOrKey} with one of your issue ids or keys.

Now we need to configure the authentication, headers and the comment itself. Head over to the Authorization tab, then select Basic Auth (Please note that this is getting deprecated by Atlassian). Pick a user with the correct permission setup and fill in the username and password.

Then go to the Headers tab and add Content-Type as a key and application/json as the corresponding value. Finally, go to the tab Body, select raw and add the following query parameter as the body below.

Click Send and you will receive a parsed response in JSON with a status 201 (created) if it was successful.

Adding comments to multiple issues

We have successfully added our comment to a single issue. Now, we would like to do the same thing for 10, 100, 1000 issues or even more. How do we do that? Can we add comment based data coming from a CSV?

To transform our single value request into taking a list of values isn’t that difficult. Start by going into your request and changing the issue key to a variable using double curly brackets: {{issuekey}}. We also need to create a variable for the comment body itself, so go to the headers tab and set {{comment}} as the key.

In order to loop over the API calls, we are going to use what Postman refers to as a Collection Runner, or Runner for short. This will iterate all requests from a collection using input parameters provided from a CSV. It’s a powerful tool to automate REST API calls and will work well in our attempt to add comments to multiple issues.

Prepare a CVS with two columns: issuekey and comment. These columns have to match exactly to the variables names which was set in the previous steps. Then populate the CVS with a few values and it will be ready to go.

Make, move or delete any other request that you might have in your current collection before starting the runner, since these also will be executed once the runner starts. After that, click the Runner button on the top left corner and a runner window will come up. Select your collection, CSV and then click Start Run.

We now have demonstrated a few examples of using the Jira Cloud REST API. If you still have questions, don’t hesitate to leave a coment below or get in touch with one of our Atlassian certified consultants.