I'm currently writing a simple Python script which reads data from an Excel sheet and creates Jira tasks based on that data. I've got the Excel data-reading part working and the Jira task creation mostly as well, but am struggling with a couple of fields.
The following fields are mandatory for our Jira tasks:
I got the first six working with the following line of code in Python:
issue = jira.create_issue(project=pro, summary=sum, issuetype=type, customfield_13700 = { "name": parent }, priority = {'name': priority}, customfield_12501 = external_bid )
However, I am not sure how to fill in the other parameters of the jira.create_issue function for the fix versions/s, component and due date bid fields.
I've tried many different things:
For the fix version field:
issue = jira.create_issue(fixversion=fixversion )
issue = jira.create_issue(fixversion = {'name': fixversion})
issue = jira.create_issue(fixversion = {'value': fixversion})
which all results in the following error: "errors":{"fixversion":"Field 'fixversion' cannot be set. It is not on the appropriate screen, or unknown."}}
For the component field:
issue = jira.create_issue(component = component )
issue = jira.create_issue(component = {'name': component} )
issue = jira.create_issue(fixversion = {'value': component})
Which again all results in the following error: errors":{"component":"Field 'component' cannot be set. It is not on the appropriate screen, or unknown."}}
For the due date:
issue = jira.create_issue(duedate = duedate)
issue = jira.create_issue(duedate = {'name': duedate} )
issue = jira.create_issue(duedate = {'value': duedate} )
Which gives the following error: TypeError: Object of type 'datetime' is not JSON serializable
At this point, I've tried a host of different things and looked a bunch of stuff up, most of which point to this page:
JIRA projects may contain many different issue types. Some issue screens have different requirements for fields in a new issue. This information is available through the ‘createmeta’ method. Further examples are available here.
Which isn't really helpful for me. Anybody have any idea how to best proceed from here?
The error TypeError: Object of type 'datetime' is not JSON serializable
is issued when you try to serialize a datetime object into a JSON object.
The duedate
value you use is a datetime object. Whenever you try to dump a dictionary containing a datetime object to a JSON object, you will encounter this error. Example below:
import datetime
test = {}
test['date'] = datetime.datetime.now()
import json
json.dumps(test)
To avoid this error, convert your datetime object to an object that is accepted by the Javascript Object Notation (JSON) standard. Such as a string.
test['date'] = str(datetime.datetime.now())
json.dumps(test)
Do note that direct conversion from your datetime object might not fit the JIRA format for accepted dates. Use the correct format when casting to string (give the datetime documentation a look)