Jira REST API Tutorial
Introduction
The Jira REST API provides a powerful way to interact with Jira programmatically. It allows developers to access the functionality of Jira from external applications, enabling automation, integration with other systems, and custom solutions. This tutorial will walk you through the essentials of using the Jira REST API, from setting up authentication to performing common tasks.
Authentication
To interact with the Jira REST API, you need to authenticate your requests. There are several methods for authenticating, including Basic Authentication and OAuth. For simplicity, we'll use Basic Authentication, which requires your Jira username and an API token.
Example: Basic Authentication
Use the following format to authenticate your requests:
curl -D- -u email@example.com:API_TOKEN -X GET -H "Content-Type: application/json" https://your-domain.atlassian.net/rest/api/3/issue/ISSUE-KEY
Creating an Issue
One of the most common tasks is creating an issue in Jira. To do this, you need to send a POST request to the /rest/api/3/issue endpoint with the issue details in the request body.
Example: Creating an Issue
curl -D- -u email@example.com:API_TOKEN -X POST -H "Content-Type: application/json" --data '{
"fields": {
"project": {
"key": "PROJECT_KEY"
},
"summary": "Issue summary",
"description": "Issue description",
"issuetype": {
"name": "Task"
}
}
}' https://your-domain.atlassian.net/rest/api/3/issue
Updating an Issue
To update an existing issue, send a PUT request to the /rest/api/3/issue/ISSUE-KEY endpoint with the updated fields in the request body.
Example: Updating an Issue
curl -D- -u email@example.com:API_TOKEN -X PUT -H "Content-Type: application/json" --data '{
"fields": {
"summary": "Updated summary",
"description": "Updated description"
}
}' https://your-domain.atlassian.net/rest/api/3/issue/ISSUE-KEY
Fetching Issue Details
You can fetch details of a specific issue by sending a GET request to the /rest/api/3/issue/ISSUE-KEY endpoint.
Example: Fetching Issue Details
curl -D- -u email@example.com:API_TOKEN -X GET -H "Content-Type: application/json" https://your-domain.atlassian.net/rest/api/3/issue/ISSUE-KEY
{ "id": "10000", "key": "PROJECT-1", "fields": { "summary": "Issue summary", "description": "Issue description", "issuetype": { "name": "Task" } // More fields... } }
Deleting an Issue
To delete an issue, send a DELETE request to the /rest/api/3/issue/ISSUE-KEY endpoint.
Example: Deleting an Issue
curl -D- -u email@example.com:API_TOKEN -X DELETE -H "Content-Type: application/json" https://your-domain.atlassian.net/rest/api/3/issue/ISSUE-KEY
Searching for Issues
To search for issues, you can use JQL (Jira Query Language) with the /rest/api/3/search endpoint. This allows you to filter issues based on various criteria.
Example: Searching for Issues
curl -D- -u email@example.com:API_TOKEN -X GET -H "Content-Type: application/json" 'https://your-domain.atlassian.net/rest/api/3/search?jql=project=PROJECT_KEY AND status="To Do"'
{ "issues": [ { "id": "10001", "key": "PROJECT-2", "fields": { "summary": "Issue 2 summary", "status": { "name": "To Do" } } } // More issues... ] }
Conclusion
This tutorial covered the basics of using the Jira REST API, including authentication, creating, updating, fetching, deleting, and searching for issues. The Jira REST API provides extensive capabilities, and you can explore further by referring to the official Jira REST API documentation.