I'm creating JIRA issues dynamically from my script using Jira REST APIs. In this script, the user can provide the values for the issue fields. Using that information, I'm creating a JSON that is required by the API. But the problem is that not all the fields have the same JSON structure. Some of the fields require nested JSON and some do not, even if the data type is the same.
For, example, the "summary" field does not require nested JSON, but the "description" field requires an Atlassian document JSON structure.
{
'fields': {
'summary': mappings['summary'],
"issuetype": {
"name": issue_type
},
'project': {
'id': project_id
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": mappings['description'],
"type": "text"
}
]
}
]
}
}
}
Also, the "project" and "issueType" unnecessarily requires the object.
As I'm dynamically creating this JSON structure, how do I know what structure is required by which field?
I couldn't find documentation about this. I'm using this endpoing: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post
Thanks!
@kaushal2896 Yes this bit of hassle to correctly know the structure of fields.
But it remain constant for most standard fields.
Also you use metadata api to guess some details - https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-createmeta-get
You can also take a look at SDK's available for Jira API in multiple languages.
I checked that "createmeta" call, it returns "schema" object for most of the fields, which has a datatype attribute named "type". But the problem is in the fields having type string. Some of the fields are plain text and some fields are Atlassian documents, which require specific JSON (in REST API v3). So how do I know this in a dynamic setting?
In my script, the user only enters the plain string for all string fields and I've to determine such variations in a single data type dynamically and which looks impossible as of now.
This is just an example of a string type. Not sure if such inconsistencies are there for other types as well.
I don't think this will be handled by any of the SDK because of this behavior of Jira APIs.
Also, there are so many types available for custom fields and I think hardcoding JSON structure for each field is not feasible. Is there a simpler way to achieve this dynamically?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@kaushal2896 This is only thing I can say,
Rest depend upon code you write. I know this is pretty difficult but you have to manage.
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.