Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I know the data types and expected JSON format for all issue fields

kaushal2896
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 18, 2020

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!

1 answer

1 accepted

2 votes
Answer accepted
DPKJ
Community Champion
September 18, 2020

@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.

kaushal2896
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 24, 2020

@DPKJ 

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?

DPKJ
Community Champion
September 25, 2020

@kaushal2896 This is only thing I can say,

  • All standard fields like, summary, description, status, type, assignee, reporter  etc will remain same and are not changing in near future, so can create your own structure for them.
  • In case of custom fields, only pointer I can give is type of field.

Rest depend upon code you write. I know this is pretty difficult but you have to manage.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events