How to use POST on the Feature/Epic custom fields in the Jira Align API v2
Summary
With the release of v.10.104.x, we support Custom Fields for Epics and Features in the REST API v2.
This article outlines how to update the values using the API POST command.
Solution
First of all, it is good to run the call to the editmeta endpoint, as it will bring the information needed on the custom field and its type, which is necessary to be used on the PATCH. This endpoint can be found for Epics at:
<https://<instance>.jiraalign.com/rest/align/api/2/Epics/<id>/editmeta>
The field customfields is an array that holds the position (and values) of all the customfield_xxxxx inside of it, to be able to access these elements individually, the position inside the array needs to be provided. Keep in mind that this array starts at position 0.
Using the editmeta output from the above example, field customfield_70026 is on position 0 of array customfields, as customfield_70027 is on position 1.
Also, as this is a structure of JSON (so you have elements inside elements), the fields customfield_xxxxx can also be arrays themselves and will have their values inside of specific positions. Due to this, it is important to get the editmeta output to be able to understand its structure and how to manipulate it.
Custom Field type Text
For a text type, we can simply add it like the below on the normal JSON body that would be used:
"customFields":
[
{
"customfield_80060":
[
{
"value": "my test"
}
]
}
]
If we use a complete request, it would look like this for Features:
{
"title": "Diego Test Feature Created by API 1",
"description": "Diego Test Feature Created by API 1",
"releaseId": null,
"ownerId": "661727",
"state": 0,
"createDate": "2022-05-12T14:52:15Z",
"type": 1,
"mmf": 0,
"isBlocked": 0,
"priority": null,
"primaryProgramId": 196,
"productId": null,
"isMultiProgram": null,
"themeId": null,
"parentId": null,
"reportColor": "#046895",
"startSprintId": null,
"endSprintId": null,
"targetCompletionDate": null,
"startInitiationDate": null,
"portfolioAskDate": null,
"featureSummary": "Diego Test Epic to Break Integration 6",
"customFields":
[
{
"customfield_90690":
[
{
"value": "Diego Test Custom String Field 1"
}
]
}
]
}
The POST command would be similar to:
curl -k -X POST "https://alignsupport.jiraalign.com/rest/align/api/2/Feature/{id}" -H "accept: */*" -H "Authorization: bearer {TOKEN}" -H "Content-Type: application/json;odata.metadata=minimal;odata.streaming=true" -d "@{CONTENT_FILE}"
Custom Field type Dropdown
The POST for Dropdown fields is similar, with the difference that we need to add the id of the option as the value (this can be seen on the editmeta output as well), on this example, the field updated is customfield_90756 :
"customFields": [
{
"customfield_90756": [
{
"id": 18,
}
]
}
]
A complete request would look like this for Features:
{
"title": "Diego Test Feature Created by API 1",
"description": "Diego Test Feature Created by API 1",
"releaseId": null,
"ownerId": "661727",
"state": 0,
"createDate": "2022-05-12T14:52:15Z",
"type": 1,
"mmf": 0,
"isBlocked": 0,
"priority": null,
"primaryProgramId": 196,
"productId": null,
"isMultiProgram": null,
"themeId": null,
"parentId": null,
"reportColor": "#046895",
"startSprintId": null,
"endSprintId": null,
"targetCompletionDate": null,
"startInitiationDate": null,
"portfolioAskDate": null,
"featureSummary": "Diego Test Epic to Break Integration 6",
"customFields": [
{
"customfield_90756": [
{
"id": 18,
}
]
}
}
Using the POST command like the previous one.
With Both types:
One simple example with both types would look like this:
"customFields": [
{
"customfield_90692": null
},
{
"customfield_90756": [
{
"id": 18,
}
]
},
{
"customfield_90690": [
{
"value": "Diego Test Custom String Field 1"
}
]
},
{
"customfield_90691": null
}
]