# Link Issues

Use the REST API to link issues.

## Summary

To link one issue to another, apply a command to the target issue.

Make a POST request to the `/api/commands` endpoint with the body containing the ID of the target issue and the command query.

## Step-by-Step

Procedure:

1. To apply a command to an issue, make a POST request to the following endpoint: `/api/commands`.

Example:

```CURL
curl -X POST 'https://example.youtrack.cloud/api/commands' \
-H 'Authorization: Bearer <YouTrack_token>' \
-H 'Content-Type: application/json' \
-d '{
"query": "relates to NP-92",
"issues": [
{
"idReadable": "NP-113"
}
]
}'
```

2. In the body of the request, pass a command query and the ID of the issue that you need to apply this command to.

```JSON
{
    "query": "relates to NP-92",
    "issues": [
        {
            "idReadable": "NP-113"
        }
    ]
}
```

> **Tip:**
> For more information about applying commands with the REST API, see [Apply Commands to Issues](api-usecase-commands.html). For command syntax, see the [command reference](https://www.jetbrains.com.cn/en-us/help/youtrack/cloud/command-reference.html).

3. To check whether the command was applied successfully, make a GET request to the endpoint `/api/issues/NP-113/links` where `NP-113` is the ID of the target issue.

Specify link attributes in the `fields` parameter of your request.

Example:

```CURL
GET https://example.youtrack.cloud/api/issues/NP-113/links?fields=linkType(name,sourceToTarget,targetToSource),issues(id,idReadable,summary)
```

The expected server response is:

```JSON
[
  {
    "linkType": {
      "sourceToTarget": "relates to",
      "targetToSource": "",
      "name": "Relates",
      "$type": "IssueLinkType"
    },
    "issues": [
      {
        "idReadable": "NP-92",
        "summary": "Failed test",
        "id": "99-543",
        "$type": "Issue"
      }
    ],
    "$type": "IssueLink"
  },
  ...
]
```

