I am trying to use the Jira Rest API to gather data from Jira tickets in my project using python. I want to be able to collect the comments, custom fields, and summary/key.
import pandas as pd
import requests
from requests.auth import HTTPBasicAuth
import json
from concurrent.futures import ThreadPoolExecutor
pat = "ACCESS TOKEN"
email = "EMAIL"
auth = HTTPBasicAuth(email, pat)
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
base_payload = {
"expand": [
"names",
"schema",
"operations"
],
"fields": [
"key",
"comment"
],
"fieldsByKeys": False,
"jql": 'project = PROJECT NAME',
"maxResults": 100,
"startAt": 0
}
def fetch_issues_chunk(start_at):
payload = base_payload.copy()
payload["startAt"] = start_at
payload = json.dumps(payload)
response = requests.request("POST", url, data=payload, headers=headers, auth=auth)
if response.status_code != 200:
print(f"Request failed with status code: {response.status_code}, message: {response.text}")
return []
data = response.json()
return data.get("issues", [])
def fetch_all_issues(url, headers, base_payload, auth):
initial_response = requests.request("POST", url, data=json.dumps(base_payload), headers=headers, auth=auth)
if initial_response.status_code != 200:
print(f"Initial request failed with status code: {initial_response.status_code}, message: {initial_response.text}")
return []
initial_data = initial_response.json()
total = initial_data.get("total", 0)
issues = initial_data.get("issues", [])
with ThreadPoolExecutor() as executor:
futures = [executor.submit(fetch_issues_chunk, start_at) for start_at in range(100, total, 100)]
for future in futures:
issues.extend(future.result())
return issues
# Fetch all issues
issues = fetch_all_issues(url, headers, base_payload, auth)
And this continues to return a 400 code for me [Initial request failed with status code: 400, message: {"errorMessages":["Invalid request payload. Refer to the REST API documentation and try again."]}] and I am not sure why.. TIA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.