JIRA exposes many of its features through a set of REST APIs, allowing other applications to interact with it. With these APIs, you can perform operations such as searching, creating, and deleting issues. In fact, several of the add-ons used throughout this book make use of these REST APIs to perform their functions.
Being a web-based standard, JIRA's REST API allows you to use any technology with it. This means, you can write the code in Java, .NET, JavaScript, or even with simple bash scripts.
In this recipe, we will be using the RESTClient Firefox add-on to run a search query against JIRA for getting a list of issues assigned to the currently logged-in user. There are many other tools you can use, such as cURL, and Postman for Chrome.
Perform the following steps to run a search query using JIRA's REST API:
http://localhost:8080/rest/api/2/search?jql=assignee=currentUser()
. Make sure to change the URL to your JIRA instance.You should see the result of the API call under the Response section. Select the Response Body (Highlight) tag to see the result as formatted JSON, as shown in the following screenshot:
JIRA's REST APIs always follow the URI structure of http://host:port/context/rest/api-name/api-version/resource-name
. So, in our example, we are using version 2 of the search API. The jql parameter contains the actual JQL query we are running. Most APIs will require you to be logged in, so we configure to use Basic authentication as part of our API call.
There is an add-on called Atlassian REST API Browser that you can install in JIRA, which allows you to interact with your JIRA's REST APIs directly in a browser. You can install this add-on from the following link:
https://marketplace.atlassian.com/plugins/com.atlassian.labs.rest-api-browser/server/overview
After you have installed the add-on, you can open your browser and go to
http://your_jira_instance/plugins/servlet/restbrowser
. As shown in the next screenshot, you should see an API browser interface. On the left-hand side, you will see a full list of the REST APIs that are available in your JIRA instance (based on its version). On clicking on any of the APIs, the browser will present you with all the parameters and options available, so you will no longer need to manually find out what they are. This allows you to test and experiment with the APIs quickly, without having to write any code upfront, or using any additional tools.