Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Tamanna Godara Community Manager Feb 02, 2021

Great going @Pramodh !!!!! 

Like # people like this
Pramodh Community Leader Feb 02, 2021

Thank you @Tamanna Godara !

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

Like Pramodh likes this
Vero Rivas Community Leader Feb 02, 2021

Thanks @Pramodh 

Like Pramodh likes this

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 likes this

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

Like Pramodh likes this
Taranjeet Singh Community Leader Feb 24, 2021

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

Like Pramodh likes this

Really cool stuff, thanks! 

Like Pramodh likes this

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

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

156 views 2 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you