Basics of API in Jira, Confluence and Bitbucket

How many times have you thought in your mind the tasks that were given to you or the tasks that you would do via User Interface in your company whether they can be achieved via API/Automation?
Here's an article that will get you started on the basics of the API journey in Atlassian products.

We will look at creating basic elements in Jira, Confluence, and Bitbucket

Let me start with Jira, it's the issue
To create an issue

curl --request POST \
--url 'https://your-site.atlassian.net/rest/api/3/issue' \
--user 'your-email:api-token' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"fields" : {"summary" : "Issue Summary - Test",
"issuetype" : {"id" : "10000"},
"project" : {"id" : "10000"},
"assignee" : {"id" : "5d36b583beedf60c26aa372d"} } }'


Where to get the details like token, issue type ID, a project ID, assignee ID?


The token can be generated here
https://id.atlassian.com/manage-profile/security/api-tokens

Here's the link that will help you in getting Project ID
https://confluence.atlassian.com/jirakb/how-to-get-project-id-from-the-jira-user-interface-827341414.html

With API, to get project ID it goes like this

curl --request GET \
--url 'https://your-domain.atlassian.net/rest/api/3/project/{projectKey}' \
--user 'your-email:api-token' \
--header 'Accept: application/json'
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-projects/#api-rest-api-3-project-projectidorkey-get

Issue ID

curl --request GET \
--url 'https://your-domain.atlassian.net/rest/api/3/issuetype' \
--user 'your-email:api-token' \
--header 'Accept: application/json'

Get Account ID of Users

curl --request GET \
--url 'https://your-domain.atlassian.com/rest/api/3/user/bulk/migration' \
--user 'your-email:api-token' \
--header 'Accept: application/json'


Now that you have all the fields to create an issue, fill in the values and create an issue!


Explore more and master yourself in API!
The link to API documentation is here
https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro


How to create Confluence pages using API?
To create an empty page

curl --request POST \
--url 'https://your-domain.atlassian.net/wiki/rest/api/content' \
--user 'your-email:api-token' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"title": "Page title", "type": "page", "space": {"key": "spaceKey"}, "status": "current"}'

Here's how you would add the data in API

curl --request POST \
--url 'https://your-domain.atlassian.net/wiki/rest/api/content' \
--user 'your-email:api-token' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"title": "Page title", "type": "page", "space": {"key": "spaceKey"}, "status": "current", "body":{"storage":{"value":"<p>This is a new page</p>", "representation":"storage" }}}'

The confluence REST API documentation is here
https://developer.atlassian.com/cloud/confluence/rest/intro

Now let's go with Bitbucket
Creating a Private Repository

curl -X POST \
--url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo-name}' \
--user 'bitbucket-username:app-password' \
--header "Content-Type: application/json" \
--data '{"scm": "git", "project": {"key": "projectKey"}, "is_private": true }'


The Bitbucket API Documentation is here
https://developer.atlassian.com/bitbucket/api/2/reference

I hope you find this article gets a motivation to start with API in your instance. Please share your thoughts in the comments.

Thanks,
Pramodh

9 comments

Comment

Log in or Sign up to comment
Tamanna Godara
Community Manager
Community Managers are Atlassian Team members who specifically run and moderate Atlassian communities. Feel free to say hello!
February 2, 2021

Great going @Pramodh M !!!!! 

Like # people like this
Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 2, 2021

Thank you @Tamanna Godara !

Aishwarya Rajendra February 2, 2021

This article is really informative! Great work!!@Pramodh M 

Like Pramodh M likes this
Vero Rivas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2021

Thanks @Pramodh M 

Like Pramodh M likes this
Alexander Eck [Tempo]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2021

I have promoted this approach quiet often for our customers and especially when it comes to bulk update or bulk insert. On top of your great article I would like to add to the discussion that it is easy to populate curl commands with excel, copy-paste them into a text file and execute it from the terminal (e.g sh mycurltextfile.sh). 

View an example from our documentation here.

BR

Like Pramodh M likes this
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2021

Great sum-up @Pramodh M I will use it as a starting point when answering REST API questions :).

Like Pramodh M likes this
Taranjeet Singh
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 24, 2021

Thanks @Pramodh M ! This is really useful for beginners in Atlassian REST API, like me.

Like Pramodh M likes this
Daniel Martinez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 26, 2021

Really cool stuff, thanks! 

Like Pramodh M likes this
Kristin Lyons
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 16, 2021

Is it possible to get the results output in a list format?

Like Pramodh M likes this
TAGS
AUG Leaders

Atlassian Community Events