Clear Values of Custom Fields
Use Case
Use the REST API to clear values of issue custom fields.
Summary
To clear a value of an issue custom field:
Make sure that the target issue custom field can have an empty value.
Use Update Issue request:
POST /api/issues/{issueID}?[fields]In the
fieldsrequest parameter specify fields you want to get in response. For example, field id and full value info. This will help you to confirm that your changes are applied.In the request body specify the
idorname, and$typefor required field. Passnullforvalue.
Step-by-Step
Optional. To be sure that the target issue field can have an empty value, send a
GETrequest to the server:curl -X GET \ 'https://example.youtrack.cloud/api/issues/2-7/customFields?fields=id,projectCustomField(canBeEmpty,field(name))' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer perm:am9obi5kb2U=.UG9zdG1hbiBKb2huIERvZQ==.jJe0eYhhkV271j1lCpfknNYOEakNk7' \ -H 'Content-Type: application/json' \ -H 'cache-control: no-cache'To the sample request above, the server sends a response with the following body:
[ { "projectCustomField": { "canBeEmpty": false, "field": { "name": "Priority", "$type": "CustomField" }, "$type": "EnumProjectCustomField" }, "id": "92-1", "$type": "SingleEnumIssueCustomField" }, { "projectCustomField": { "canBeEmpty": false, "field": { "name": "Type", "$type": "CustomField" }, "$type": "EnumProjectCustomField" }, "id": "92-2", "$type": "SingleEnumIssueCustomField" }, { "projectCustomField": { "canBeEmpty": false, "field": { "name": "State", "$type": "CustomField" }, "$type": "StateProjectCustomField" }, "id": "92-3", "$type": "StateIssueCustomField" }, { "projectCustomField": { "canBeEmpty": true, "field": { "name": "Assignee", "$type": "CustomField" }, "$type": "UserProjectCustomField" }, "id": "94-0", "$type": "SingleUserIssueCustomField" }, { "projectCustomField": { "canBeEmpty": true, "field": { "name": "Subsystem", "$type": "CustomField" }, "$type": "OwnedProjectCustomField" }, "id": "92-0", "$type": "SingleOwnedIssueCustomField" }, { "projectCustomField": { "canBeEmpty": true, "field": { "name": "Fix versions", "$type": "CustomField" }, "$type": "VersionProjectCustomField" }, "id": "92-4", "$type": "MultiVersionIssueCustomField" }, { "projectCustomField": { "canBeEmpty": true, "field": { "name": "Affected versions", "$type": "CustomField" }, "$type": "VersionProjectCustomField" }, "id": "92-5", "$type": "MultiVersionIssueCustomField" }, { "projectCustomField": { "canBeEmpty": true, "field": { "name": "Fixed in build", "$type": "CustomField" }, "$type": "BuildProjectCustomField" }, "id": "92-6", "$type": "SingleBuildIssueCustomField" } ]To clear the value of the
Subsystemissue field, send aPOSTrequest as follows:curl -X POST \ 'https://example.youtrack.cloud/api/issues/2-7?fields=customFields(id,projectCustomField(field(name)),value(avatarUrl,buildLink,fullName,id,isResolved,login,minutes,name,presentation,text))' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer perm:am9obi5kb2U=.UG9zdG1hbiBKb2huIERvZQ==.jJe0eYhhkV271j1lCpfknNYOEakNk7' \ -H 'Content-Type: application/json' \ -H 'cache-control: no-cache' \ -d '{ "customFields": [ {"name":"Subsystem","$type":"SingleOwnedIssueCustomField","value":null} ] }'To confirm that the target
Subsystemfield currently is set to an empty value, let's check the response from the server. For readability, we left only the target issue field in the response body sample:{ "customFields": [ ..., { "projectCustomField": { "field": { "name": "Subsystem", "$type": "CustomField" }, "$type": "OwnedProjectCustomField" }, "value": null, "id": "92-0", "$type": "SingleOwnedIssueCustomField" }, ... ], "$type": "Issue" }