Interacting with the JIRA API

We use jira and I wanted to dump all of the comments from one project so I wrote a quick little comment scraper.

#!/usr/bin/env python

import requests
import json

url = 'https://your.jira.server/rest/api/2/'

search_url = url + 'search'

headers = {
        'Authorization': 'Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        'Content-Type': 'application/json;charset=utf-8'
    }

data = {
    "jql": "project in (ProjectNameHere)",
    "startAt": 0,
    "maxResults": 100,
    "fields": [
        "summary",
        "status",
        "assignee"
    ]
}

r = requests.get(search_url, params = data, headers=headers)

issue_json = json.loads(r.text)

issues = issue_json['issues']

issue_keys = []

issue_keys = [issue['key'] for issue in issues]

for key in issue_keys:
    comment_url = url + 'issue/' + key + '/comment'
    r = requests.get(comment_url, headers=headers, verify=False)
    issue_comments  = json.loads(r.text)
    for comment in issue_comments['comments']:
        print comment['body']

You need to update the url variable to match your jira instance and the Authorization Header with a md5hash of your usernam and password in the format user:pass

md5 user1:password1

Once you have that you can run it and dump that data to a flat file. Massage it as much as you want. I stripped out blank lines and some special characters. I wont cover sed or grep in this article.