pythonjiraatlassian-python-api

How to fetch created and updated status of JIRA ticket with Python API?


I'm trying to fetch the created and updated values from tickets in JIRA.

I'm able to pull issues using the following snippet (URL and credentials redacted):

from atlassian import Jira
import pandas as pd
import time
import glob


jira = Jira(
    url = "",
    username = "",
    password = "",
)

projects = ["PR1", "PR2", "PR3"]
FIELDS_OF_INTEREST = ["key", "fields.summary", "fields.status.name"]
timestamp = time.strftime("%Y%m%d-%H%M%S")
csv_folder = "./csvs/"
file_ending = ".csv"


for key in projects:
    output = csv_folder + key + timestamp + file_ending

    print(f"Currently processing: {key}")
    results = jira.jql(f"project = {key}", limit = 1000, fields=["issuetype", "status", "summary"])
    df = pd.json_normalize(results["issues"])
    df[FIELDS_OF_INTEREST].to_csv(output, index=False)

The objects returned, even without the FIELDS_OF_INTEREST applied, does not contain the timestamps. To get the timestamps I need to pass in expand=changelog. But when I do that I no longer get the same structure I'm looking for. The created and updated information is available then though.

The following snippet is the one I'm currently using trying to extract the timestamp (URL and credentials redacted):

from atlassian import Jira
import pandas as pd
import time
import glob


jira = Jira(
    url = "",
    username = "",
    password = "",
)


projects = ["PR1", "PR2", "PR3"]

for key in projects:
    issues = jira.jql(f"project=  {key}", limit = 5, expand='changelog')
    df = pd.json_normalize(issues)
    df.to_csv("changelog.csv", index=False)

I'm not sure if I'm doing it right. I would love to be able to know how to pull these data points.

I'm unable to find any examples in: https://github.com/atlassian-api/atlassian-python-api/tree/master/examples/jira or in the documentation.

Any help is appreciated!


Solution

  • You have to do more inspection to get the actual dates and timestamps you are looking for

    The example most relevant is probably from the ReportGenerator.

    In the JQL, created is added to the fields list, and the changelog is expanded. See this section.

    After that, in the main execution, the histories are inspected for the changes/and their dates, and emitted.