I need to connect Jira data to an external data source to get a complete picture of all the efforts underway. I have tried multiple solutions just to get the Jira data, each ending up overly complicated.
I don't mind using curl to retrieve the data but it would be nice to just keep everything in Python. Unfortunately the system admins aren't expert in the security intricacies so they pointed me here, to the Atlassian community boards. If I have to use curl, that's fine, but I find I'm building it out by trial and error by googling a question, trying something, googling a different question, getting more info and refining, repeat until done ... which seems a long way off. Even then, I'll probably have to do the same thing in Python to read the JSON output.
There has got to be a better way, I hope. If it helps, below is the curl request I've built up so far (minus anything proprietary, of course). Any wisdom or advice is greatly appreciated.
curl -D- -H "Authorization: Basic xxxxxxxxxxxxxx==" -X POST -d "{\"jql\": \"'project' = 'MYPROJ' AND 'issuetype' = 'Milestone'\",\"fields\":[\"key\"]}" -H "Content-Type: application/json" --url "https://theprocess.thecompany.com/rest/api/2/search"
You have to build your output data structure first if you're going to connect Jira to an external data source. If you want a flat CSV file, you will need to know the exact fields you want to be placed on that file. An easy way to do this in python would be
Just thinking about this, I came up with this script as an example which is completely expandable based on what fields you want.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So, on point 3, there's a simple answer - tell it what fields you want to fetch (if you don't, Jira assumes "everything"). See https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-search/#api-rest-api-3-search-get and look for the "fields" parameter.
For the "keep it in python", that's not really an Atlassian question, but I have "learn python" on my to-do list, and I've wandered through several sites that try to explain how to do some things in python. I can't say this is "the best" or even that I've tried to follow it, I've just bookmarked it for later, but https://www.nylas.com/blog/use-python-requests-module-rest-apis/ looks like a quick way to get started using REST APIs in Python.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Nic, for the reply. I tried the suggestion.
Here is what I used:
curl -D- -H "Authorization: Basic xxxxxxxxxxxxxxxx==" -X POST -d "{\"jql\": \"'project' = 'MYPROJ' AND 'issuetype' = 'Milestone'\",\"fields\":[\"key\", \"status\"] }" -H "Content-Type: application/json" --url "https://xxxx.yyyy.com/rest/api/2/search"
What I got back was more than I hoped. Here is the beginning of the response:
{"expand":"schema,names","startAt":0,"maxResults":50,"total":11364,"issues":[{"expand":"operations,versionedRepresentations,editmeta,changelog,renderedFields","id":"541422","self":"https://xxxx.yyyy.com/rest/api/2/issue/541422","key":"MYPROJ-12345","fields":{"status":{"self":"https://xxxx.yyyy.com/rest/api/2/status/10000","description":"","iconUrl":"https://xxxx.yyyy.com/images/icons/subtask.gif","name":"To Do","id":"10000","statusCategory":{"self":"https://xxxx.yyyy.com/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"To Do"}}}}
Any thoughts on how to get this down to just
"key":"MYPROJ-12345","status":"To Do"
Your time and patience is greatly appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried adding the fields parameter as described in the first link I gave?
It will still return the metadata in the JSON, but you can easily trim that out in your code. I often work with shell scripts rather than python, using a simple executable for extracting raw data from json responses - it's called "jq" and I understand there's a library for python that does the same thing (pip install jq)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.