I have below code where i am connecting to JIRA rest api using Python which is working fine. Now i want to save this response into csv file but dont know how to do it. I am quiet new in Python code.
import requests
import json
import base64
# Base encode email and api token
cred = "Basic " + base64.b64encode(b'XXXX:XXXX').decode("utf-8")
# Set header parameters
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization" : cred
}
# Enter your project key here
projectKey = "TRT"
# Update your site url
url = "https://jira-test./rest/api/latest/search?jql=project%20%3D%20" + projectKey
# Send request and get response
response = requests.request(
"GET",
url,
headers=headers
)
# Decode Json string to Python
json_data = json.loads(response.text)
# Display issues
for item in json_data["issues"]:
print(item["id"] + "\t" + item["key"] + "\t" +
item["fields"]["issuetype"]["name"] + "\t" +
item["fields"]["created"]+ "\t" +
item["fields"]["creator"]["displayName"] + "\t" +
item["fields"]["status"]["name"] + "\t" +
item["fields"]["summary"] + "\t"
)
Below is how the output looks like:
330479 OO-27 Ad-hoc 2021-10-14T09:29:41.000+0200 TST Backlog Testing the Report
330480 OO-28 Ad-hoc 2021-10-14T09:29:41.000+0200 TST Backlog Testing the Report
330481 OO-29 Ad-hoc 2021-10-14T09:29:41.000+0200 TST Backlog Testing the Report
cvsorpandasto save it.python script.py > output.csvand it will send to file all printed text .\tas separator then you have to load CSV also with\tas separator. ie.pd.read_csv(..., sep='\t'). (normalCSVusescommaas separator - and this is why it has nameComma Separated Values)