YouTrack Standalone 2019.2 Help

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:

  1. Make sure that the target issue custom field can have an empty value.

  2. Use Update Issue request:

    POST /api/issues/{issueID}?[fields]

  3. In the fields request 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.

  4. In the request body specify the id or name, and $type for required field. Pass null for value.

Step-by-Step

  1. Optional. To be sure that the target issue field can have an empty value, send a GET request to the server:

    curl -X GET \ 'https://example.myjetbrains.com/youtrack/api/issues/2-7/customFields?fields=id,projectCustomField%28canBeEmpty,field%28name%29%29' \ -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" } ]
  2. To clear the value of the Subsystem issue field, send a POST request as follows:

    curl -X POST \ 'https://example.myjetbrains.com/youtrack/api/issues/2-7?fields=customFields%28id,projectCustomField%28field%28name%29%29,value%28avatarUrl,buildLink,fullName,id,isResolved,login,minutes,name,presentation,text%29%29' \ -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} ] }'
  3. To confirm that the target Subsystem field 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" }
Last modified: 17 July 2019