Atlassian API
curl -D- -u "$user":"$pw" -X PUT -H "Content-Type: application/json" https://$server/rest/api/2/issue/$jira_key --data '{"customfield_12345":{"value":"myValue"}}'
BASH - Jira
get all Custom fields on Jira server
curl -D- -u user:password -X GET -H "Content-Type: application/json" https://jira.instance.com/rest/api/2/field
get JSON output of an issue
curl -D- -u user:password -X GET -H "Content-Type: application/json" https://jira.instance.com/rest/api/2/search?jql=key=INFO-68
make 2 issues linked to each other
curl -u user:password -w '<%{http_code}>' -H 'Content-Type: application/json' https://jira.instance.com/rest/api/2/issueLink -X POST --data '{"type":{"name":"Related Incident"},"inwardIssue":{"key":"ISS-123"},"outwardIssue":{"key":"SYS-456"}}'
get all custom field Select child values
$ curl -u user:pw -X GET https://jira.instance.com/rest/jiracustomfieldeditorplugin/1.1/user/customfieldoptions/12600
[{"optionvalue":"Product1","id":14042,"sequence":0,"disabled":false},{"optionvalue":"Product2","id":14043,"sequence":1,"disabled":false},{"optionvalue":"Product3","id":14044,"sequence":2,"disabled":false},{"optionvalue":"Product4","id":14045,"sequence":3,"disabled":false}]
create new issue
api_data="{\"fields\":{\"project\":{\"key\":\"${project}\"},\"summary\":\"my summary\",\"description\": \"my description\",\"issuetype\":{\"name\":\"${issuetype}\"}}}"
curl -u "${jira_user}":"${jira_pw}" -w "<%{http_code}>" -H "Content-Type: application/json" https://${jira_server}/rest/api/2/issue/ -X POST --data "${api_data}")
update existing ticket, add attachment
curl -D- -u "${jira_user}":"${jira_pw}" -w "<%{http_code}>" -X POST -H "X-Atlassian-Token: nocheck" -F "file=@/tmp/attachment_file.txt" https://${jira_server}/rest/api/2/issue/${jira_key}/attachments)
update existing ticket, change assignee
curl -D- -u "$user":"$pw" -X PUT -H "Content-Type: application/json" https://$server/rest/api/2/issue/$jira_key --data '{"fields": {"assignee":{"name":"$assignee"}}}'
update existing ticket, edit customfield option value
curl -s -D -D- -u $user:$pw -X GET -H "Content-Type: application/json" http://$jira_server/rest/api/2/issue/$jira_key/transitions?expand=transitions.fields
get all Status history (dont show HTTP header in response, -s -D )
curl -D- -u user:pw -X GET -H "Content-Type: application/json" https://jira.local/rest/plugins/1.0/
Get all plugins in a JSON
curl -o out -u user:pw -X GET -H "Content-Type: application/json" "https://jira.local/rest/api/2/issue/createmeta?expand=projects.issuetypes.fields&projectKeys=PROJ1,PROJ2"
Get all fields including required fields from a project
Get all application links (Confluence, Bitbucket, Fisheye
curl -s -X GET -u username:pw -H "Accept: application/json" https://bitbucket.corp.local/rest/applinks/1.0/listApplicationlinks
Delete application link (get ID of link from step above)
curl -X DELETE -u username:pw -H "Accept: application/json" https://bitbucket.corp.local/rest/applinks/1.0/applicationlink/8796ba62-926a-38b0-ac72-3297d0c4891e
PYTHON - Jira
------------------------------------------------------------------------------------------------
## Get Jira details
def get_jira(jira_server, jira_user, jira_pw, jira_key):
print('getting jira issue %s' % jira_key)
url = 'https://' + jira_server + '/rest/api/2/issue/' + jira_key
try:
req = requests.get(url, auth=(jira_user, jira_pw), verify=False)
if not req.status_code in range(200,206):
print('Error connecting to Jira.. check config file')
sys.exit()
jira = req.json()
return jira['key']
except requests.exceptions.Timeout:
print('Timeout trying to connect to jira')
except requests.exceptions.RequestException as exep:
# catastrophic error. bail.
print('error connecting to jira: ' + str(exep))
>>> get_jira(jira_server, jira_user, jira_pw, 'SYS-123')
------------------------------------------------------------------------------------------------
## Create a new Jira
def create_jira(jira_server, jira_user, jira_pw, data):
print('creating new Jira issue')
url = 'https://' + jira_server + '/rest/api/2/issue/'
headers = {'Content-type': 'application/json'}
try:
req = requests.post(url, auth=(jira_user, jira_pw), data=data, headers=headers, verify=False)
# check return
if not req.status_code in range(200,206):
print('Error connecting to Jira.. check config file')
sys.exit()
jira = req.json()
return jira['key']
except requests.exceptions.Timeout:
print('Timeout trying to connect to jira')
except requests.exceptions.RequestException as exep:
# catastrophic error. bail.
print('error connecting to jira: ' + str(exep))
except:
print('error creating new Jira ticket')
>>> data = data = '{"fields":{"project":{"key":"SYS"}, "summary": "my Summary","assignee":{"name":"Joe.Shmoe"},"description":"my Desc","issuetype":{"name":"Task"}}}'
>>> create_jira(jira_server, jira_user, jira_pw, data)
------------------------------------------------------------------------------------------------
## Update existing Jira
def update_jira(jira_server, jira_user, jira_pw, data, jira_key):
print('updating Jira issue %s' % jira_key)
headers = {'Content-type': 'application/json'}
url = 'https://' + jira_server + '/rest/api/2/issue/' + jira_key
try:
req = requests.put(url, auth=(jira_user, jira_pw), data=data, headers=headers, verify=False)
print req.status_code
# check return
if not req.status_code in range(200,206):
print('Error connecting to Jira.. check config file')
sys.exit()
else:
print('Jira ticket %s updated successfully' % jira_key)
except requests.exceptions.Timeout:
print('Timeout trying to connect to jira')
except requests.exceptions.RequestException as exep:
# catastrophic error. bail.
print('error connecting to jira: ' + str(exep))
>>> data = {"fields": {"assignee":{"name":"Fred"}}}
>>> update_jira(jira_server, jira_user, jira_pw, data, 'SYS-123')
------------------------------------------------------------------------------------------------
## Add an Attachment
def jira_add_attachment(jira_server, jira_user, jira_pw, jira_key, attachment, filename):
print('adding attachment to jira: %s' % jira_key)
headers = {'X-Atlassian-Token': 'nocheck'}
url = 'https://' + jira_server + '/rest/api/2/issue/' + jira_key + '/attachments'
try:
req = requests.post(url, auth=(jira_user, jira_pw), files={'file':(filename, attachment)}, data={'description':'my Attachment'}, headers=headers, verify=False)
print req.status_code
# check return
if not req.status_code in range(200,206):
print('Error connecting to Jira.. check config file')
sys.exit()
else:
print('Jira ticket %s updated successfully' % jira_key)
except requests.exceptions.Timeout:
print('Timeout trying to connect to jira')
except requests.exceptions.RequestException as exep:
# catastrophic error. bail.
print('error connecting to jira: ' + str(exep))
>>>
attachments = {}
for filename in glob.glob("reports/*.zip"):
print filename
with open(filename) as f:
attachments[filename] = f.read()
jira_add_attachment(jira_server, jira_user, jira_pw, jira_key, attachments[filename], filename)
BASH - Bitbucket
get all Repos in a project
curl -u user:pw https://bitbucket.instance/rest/api/1.0/projects/<PROJ_NAME>/repos | jq .
get all Users
curl -u user:pw https://bitbucket.instance/rest/api/1.0/users | jq .
create Pull Request
data='{"title":"[SYS-123] New Jira ABC", "description":"This ticket was generated automatically: \\n blah blah blah, \
"fromRef":{"id":"refs/heads/branch_name", "repository":{"slug":"repo_name","name":null,"project":{"key":"SYS"}}}, \
"toRef":{"id":"refs/heads/production", "repository":{"slug":"repo_name","name":null,"project":{"key":"SYS"}}}, \
"reviewers": {"user": {"name": "joe"}, {"name":"fred"}}'
curl -u user:pw -X POST --data $data https://bitbucket.instance/rest/api/1.0/projects/<PROJ_NAME>/repos/<REPO NAME>/pull-requests
get all pull requests as a JSON object
curl -u user:password https://jira.instance.com/rest/api/1.0/projects/<PROJ_NAME>/repos/<REPO_NAME>/pull-requests
get all branches in a Repo
curl -u user:password https://jira.instance.com/rest/api/1.0/projects/<PROJ_NAME>/repos/<REPO_NAME>/branches
delete a branch
curl -u user:password -H "Content-Type: application/json" -d '{"name": "refs/heads/feature/PROJ-123-branchName"}' -X DELETE https://jira.instance.com/rest/branch-utils/1.0/projects/<PROJ NAME>/repos/<REPO NAME>/branches
get JSON output of an issue
curl -D- -u user:password -X GET -H "Content-Type: application/json" https://jira.instance.com/rest/api/2/search?jql=key=INFO-68
make 2 issues linked to each other
curl -u user:password -w '<%{http_code}>' -H 'Content-Type: application/json' https://jira.instance.com/rest/api/2/issueLink -X POST --data '{"type":{"name":"Related Incident"},"inwardIssue":{"key":"ISS-123"},"outwardIssue":{"key":"SYS-456"}}'
get all custom field Select child values
$ curl -u user:pw -X GET https://jira.instance.com/rest/jiracustomfieldeditorplugin/1.1/user/customfieldoptions/12600
[{"optionvalue":"Product1","id":14042,"sequence":0,"disabled":false},{"optionvalue":"Product2","id":14043,"sequence":1,"disabled":false},{"optionvalue":"Product3","id":14044,"sequence":2,"disabled":false},{"optionvalue":"Product4","id":14045,"sequence":3,"disabled":false}]
create new issue
api_data="{\"fields\":{\"project\":{\"key\":\"${project}\"},\"summary\":\"my summary\",\"description\": \"my description\",\"issuetype\":{\"name\":\"${issuetype}\"}}}"
curl -u "${jira_user}":"${jira_pw}" -w "<%{http_code}>" -H "Content-Type: application/json" https://${jira_server}/rest/api/2/issue/ -X POST --data "${api_data}")
update existing ticket, add attachment
curl -D- -u "${jira_user}":"${jira_pw}" -w "<%{http_code}>" -X POST -H "X-Atlassian-Token: nocheck" -F "file=@/tmp/attachment_file.txt" https://${jira_server}/rest/api/2/issue/${jira_key}/attachments)
update existing ticket, change assignee
curl -D- -u "$user":"$pw" -X PUT -H "Content-Type: application/json" https://$server/rest/api/2/issue/$jira_key --data '{"fields": {"assignee":{"name":"$assignee"}}}'
update existing ticket, edit customfield option value
curl -D- -u "$user":"$pw" -X PUT -H "Content-Type: application/json" https://$server/rest/api/2/issue/$jira_key --data '{"customfield_12345":{"value":"myValue"}}'
Get all application links
curl -u user:pw -H "Acccept: application/json" https://bitbucket.corp.local/rest/applinks/1.0/applicationlink
Delete an application link (get ID from above command)
curl -X DELETE -u user:pw -H "Acccept: application/json" https://bitbucket.corp.local/rest/applinks/1.0/applicationlink/<LINK ID>