# Clear Values of Custom Fields

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:

```CURL
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

Procedure:

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

```CURL
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 <YouTrack_token>' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache'
```

To the sample request above, the server sends a response with the following body:

```JSON
[
    {
        "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
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 <YouTrack_token>' \
-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:

```JSON
{
    "customFields": [
        ...,
        {
            "projectCustomField": {
                "field": {
                    "name": "Subsystem",
                    "$type": "CustomField"
                },
                "$type": "OwnedProjectCustomField"
            },
            "value": null,
            "id": "92-0",
            "$type": "SingleOwnedIssueCustomField"
        },
        ...
    ],
    "$type": "Issue"
}
```

