4

I'm trying to get json from jira api. For this I use jira package for python. It is good for getting project and issue info. But I don't know what to do if I need to get json from url like this:

/jira/rest/structure/1.0/structure.json

Here is my server-side code:

from jira.client import JIRA

jira_options = {'server': 'https://bits.example.com/jira'}

try:
    jira = JIRA(options=jira_options,
                basic_auth=('user', 'pass'))
    project =  jira.project('CTT')
    print project
    print(project.lead.displayName)
except Exception, e:
    print e.args[0]
    print "Failed to connect to JIRA"

2 Answers 2

8

TL;DR: you can access the underlying JSON representation via the raw property. E.g.:

jira = jira.JIRA(<jira server address>, basic_auth=(<username>, <password>))
issue = jira.issue('PROJ-1234')
print(issue.raw)

Longer answer: https://github.com/pycontribs/jira/blob/develop/jira/resources.py

JIRA issues and other resources are subclasses of the Resource class (see file above). One common property is raw, which as far as I can tell stores the original JSON data obtained from the JIRA REST API call.

1
  • Care to elaborate on why the -1? Sep 13, 2018 at 21:15
2

Since you are requesting a resource which isn't available in the Python API.

You will want to make use of the requests library.

import requests

response = requests.get('https://bits.example.com/jira/rest/structure/1.0/structure.json',
    auth=('user', 'pass'))

json = response.json()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.