How to add DVCS Repositories via API to Atlassian Jira

by | May 16, 2019

We had a client reach out to us, asking how they could add repositories to Jira via the API. Unfortunately, there is no official API for this, and thus, no method that Atlassian supports for doing this. We dug into the private APIs and dug up how to do this. The APIs are the same for Bitbucket, GitHub, and GitHub Enterprise. These API calls are based on the idea that you have already established a connection between Jira and your DVCS server of choice, and are now looking specifically to add repositories to sync. We’re sharing this with everyone so that you can benefit from this as well:

// This works for Bitbucket, GitHub, and  GitHub Enterprise.

// Get your repo list 
curl --request GET \
  --url http://<BASE URL>/rest/bitbucket/1.0/repositories \
  --header 'accept: application/json' \
  --header 'authorization: Basic <AUTH INFO>' 

// Add the repo to Jira to sync
curl --request POST \
  --url http://<BASEURL>/rest/bitbucket/1.0/repo/<REPO ID FROM PREVIOUS STEP>/autolink \
  --header 'authorization: Basic <AUTH INFO>' \
  --header 'content-type: application/json' \
  --data '{"payload": true}'

Please do keep in mind that this is not a supported method of doing this. If you contact Atlassian about this, they will not support you. If you need help solving advanced Atlassian challenges like this one, please reach out!

Subscribe to receive our monthly
blog posts in your inbox

Latest Blogs
Share This