# Relate issues (https://docs.capy.ai/api-reference/issues/relate-issues)

`POST https://api.capy.ai/api/v1/issues/{code}/relations`

## Authorization

Send an API key as a bearer token: `Authorization: Bearer $CAPY_API_KEY`. See https://docs.capy.ai/api-reference/authentication.md.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `code` | path | string | yes |  |

## Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `relation` | `blocked_by` \| `blocks` \| `related` | yes | `blocks`: the path issue blocks `issue`. `blocked_by`: `issue` blocks the path issue. Two issues hold one relation, so a new one replaces the old. |
| `issue` | string | yes | The other issue's code. |

## Responses

- `200` IssueDetail: `IssueDetailEncoded`
- `400` capy/InvalidRequest: `capy_InvalidRequestEncoded`
- `401` capy/Unauthorized: `capy_UnauthorizedEncoded`
- `403` capy/Forbidden: `capy_ForbiddenEncoded \| capy_ForbiddenEncoded`
- `404` capy/IssueNotFound: `capy_IssueNotFoundEncoded`
- `429` capy/RateLimited: `capy_RateLimitedEncoded`

## Example

```bash
curl -X POST "https://api.capy.ai/api/v1/issues/{code}/relations" \
  -H "Authorization: Bearer $CAPY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"relation":"blocked_by","issue":"<issue>"}'
```

## Referenced schemas

```json
{
  "IssueDetailEncoded": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "code": {
        "type": "string"
      },
      "number": {
        "type": "integer"
      },
      "projectId": {
        "type": "string"
      },
      "title": {
        "type": "string"
      },
      "state": {
        "$ref": "#/components/schemas/IssueStateRefEncoded"
      },
      "priority": {
        "anyOf": [
          {
            "type": "string",
            "enum": [
              "urgent",
              "high",
              "normal",
              "low"
            ]
          },
          {
            "$ref": "#/components/schemas/UnsupportedMember_2"
          }
        ]
      },
      "dueAt": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ]
      },
      "parentId": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ]
      },
      "visibility": {
        "anyOf": [
          {
            "type": "string",
            "enum": [
              "org",
              "private"
            ]
          },
          {
            "$ref": "#/components/schemas/UnsupportedMember_3"
          }
        ]
      },
      "assignees": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/IssueActorEncoded"
        }
      },
      "labels": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/IssueLabelRefEncoded"
        }
      },
      "subIssueCount": {
        "type": "integer"
      },
      "closedSubIssueCount": {
        "type": "integer"
      },
      "openBlockerCount": {
        "type": "integer",
        "description": "Open issues the key can read that block this one."
      },
      "createdAt": {
        "type": "string"
      },
      "updatedAt": {
        "type": "string"
      },
      "closedAt": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ]
      },
      "description": {
        "type": "string",
        "description": "Markdown. An embedded file appears as `capy-file:<fileId>`, one of `files`."
      },
      "creator": {
        "anyOf": [
          {
            "$ref": "#/components/schemas/IssueActorEncoded"
          },
          {
            "type": "null"
          }
        ]
      },
      "parent": {
        "anyOf": [
          {
            "$ref": "#/components/schemas/IssueEncoded"
          },
          {
            "type": "null"
          }
        ]
      },
      "subIssues": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/IssueEncoded"
        }
      },
      "pullRequests": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/IssuePullRequestEncoded"
        }
      },
      "threads": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/IssueThreadEncoded"
        }
      },
      "files": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/IssueFileEncoded"
        }
      }
    },
    "required": [
      "id",
      "code",
      "number",
      "projectId",
      "title",
      "state",
      "priority",
      "dueAt",
      "parentId",
      "visibility",
      "assignees",
      "labels",
      "subIssueCount",
      "closedSubIssueCount",
      "openBlockerCount",
      "createdAt",
      "updatedAt",
      "closedAt",
      "description",
      "creator",
      "parent",
      "subIssues",
      "pullRequests",
      "threads",
      "files"
    ],
    "additionalProperties": false
  },
  "IssueStateRefEncoded": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "name": {
        "type": "string"
      },
      "type": {
        "anyOf": [
          {
            "type": "string",
            "enum": [
              "open",
              "closed"
            ]
          },
          {
            "$ref": "#/components/schemas/UnsupportedMember_1"
          }
        ]
      }
    },
    "required": [
      "id",
      "name",
      "type"
    ],
    "additionalProperties": false
  },
  "UnsupportedMember_1": {
    "type": "string"
  },
  "UnsupportedMember_2": {
    "type": "string"
  },
  "UnsupportedMember_3": {
    "type": "string"
  },
  "IssueActorEncoded": {
    "type": "object",
    "properties": {
      "kind": {
        "anyOf": [
          {
            "type": "string",
            "enum": [
              "user",
              "thread"
            ]
          },
          {
            "$ref": "#/components/schemas/UnsupportedMember_4"
          }
        ]
      },
      "id": {
        "type": "string",
        "description": "A user id for `user`, resolved by `GET /users`, or a thread id for `thread`."
      },
      "code": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ],
        "description": "The thread's reference, such as `SCO-123`; null for a user or a thread the key cannot read."
      }
    },
    "required": [
      "kind",
      "id",
      "code"
    ],
    "additionalProperties": false
  },
  "UnsupportedMember_4": {
    "type": "string"
  },
  "IssueLabelRefEncoded": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "name": {
        "type": "string"
      }
    },
    "required": [
      "id",
      "name"
    ],
    "additionalProperties": false
  },
  "IssueEncoded": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "code": {
        "type": "string"
      },
      "number": {
        "type": "integer"
      },
      "projectId": {
        "type": "string"
      },
      "title": {
        "type": "string"
      },
      "state": {
        "$ref": "#/components/schemas/IssueStateRefEncoded"
      },
      "priority": {
        "anyOf": [
          {
            "type": "string",
            "enum": [
              "urgent",
              "high",
              "normal",
              "low"
            ]
          },
          {
            "$ref": "#/components/schemas/UnsupportedMember_2"
          }
        ]
      },
      "dueAt": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ]
      },
      "parentId": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ]
      },
      "visibility": {
        "anyOf": [
          {
            "type": "string",
            "enum": [
              "org",
              "private"
            ]
          },
          {
            "$ref": "#/components/schemas/UnsupportedMember_3"
          }
        ]
      },
      "assignees": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/IssueActorEncoded"
        }
      },
      "labels": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/IssueLabelRefEncoded"
        }
      },
      "subIssueCount": {
        "type": "integer"
      },
      "closedSubIssueCount": {
        "type": "integer"
      },
      "openBlockerCount": {
        "type": "integer",
        "description": "Open issues the key can read that block this one."
      },
      "createdAt": {
        "type": "string"
      },
      "updatedAt": {
        "type": "string"
      },
      "closedAt": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ]
      }
    },
    "required": [
      "id",
      "code",
      "number",
      "projectId",
      "title",
      "state",
      "priority",
      "dueAt",
      "parentId",
      "visibility",
      "assignees",
      "labels",
      "subIssueCount",
      "closedSubIssueCount",
      "openBlockerCount",
      "createdAt",
      "updatedAt",
      "closedAt"
    ],
    "additionalProperties": false
  },
  "IssuePullRequestEncoded": {
    "type": "object",
    "properties": {
      "repoFullName": {
        "type": "string"
      },
      "number": {
        "type": "integer"
      },
      "state": {
        "anyOf": [
          {
            "type": "string",
            "enum": [
              "open",
              "draft",
              "merged",
              "closed"
            ]
          },
          {
            "$ref": "#/components/schemas/UnsupportedMember_5"
          }
        ]
      }
    },
    "required": [
      "repoFullName",
      "number",
      "state"
    ],
    "additionalProperties": false
  },
  "UnsupportedMember_5": {
    "type": "string"
  },
  "IssueThreadEncoded": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "code": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ]
      }
    },
    "required": [
      "id",
      "code"
    ],
    "additionalProperties": false
  },
  "IssueFileEncoded": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string",
        "description": "Pass it to `GET /issues/{code}/files/{fileId}/download`."
      },
      "name": {
        "type": "string"
      },
      "mediaType": {
        "type": "string"
      },
      "sizeBytes": {
        "type": "integer"
      },
      "commentId": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ],
        "description": "The comment the file came with; null for a file on the description."
      }
    },
    "required": [
      "id",
      "name",
      "mediaType",
      "sizeBytes",
      "commentId"
    ],
    "additionalProperties": false
  },
  "capy_InvalidRequestEncoded": {
    "type": "object",
    "properties": {
      "_tag": {
        "type": "string",
        "enum": [
          "capy/InvalidRequest"
        ]
      },
      "message": {
        "type": "string"
      }
    },
    "required": [
      "_tag",
      "message"
    ],
    "additionalProperties": false
  },
  "capy_UnauthorizedEncoded": {
    "type": "object",
    "properties": {
      "_tag": {
        "type": "string",
        "enum": [
          "capy/Unauthorized"
        ]
      }
    },
    "required": [
      "_tag"
    ],
    "additionalProperties": false
  },
  "capy_ForbiddenEncoded": {
    "type": "object",
    "properties": {
      "_tag": {
        "type": "string",
        "enum": [
          "capy/Forbidden"
        ]
      }
    },
    "required": [
      "_tag"
    ],
    "additionalProperties": false
  },
  "capy_IssueNotFoundEncoded": {
    "type": "object",
    "properties": {
      "_tag": {
        "type": "string",
        "enum": [
          "capy/IssueNotFound"
        ]
      }
    },
    "required": [
      "_tag"
    ],
    "additionalProperties": false
  },
  "capy_RateLimitedEncoded": {
    "type": "object",
    "properties": {
      "_tag": {
        "type": "string",
        "enum": [
          "capy/RateLimited"
        ]
      },
      "retryAfterSeconds": {
        "type": "integer"
      }
    },
    "required": [
      "_tag",
      "retryAfterSeconds"
    ],
    "additionalProperties": false
  },
  "RelateIssueRequest": {
    "type": "object",
    "properties": {
      "relation": {
        "type": "string",
        "enum": [
          "blocked_by",
          "blocks",
          "related"
        ],
        "description": "`blocks`: the path issue blocks `issue`. `blocked_by`: `issue` blocks the path issue. Two issues hold one relation, so a new one replaces the old."
      },
      "issue": {
        "type": "string",
        "minLength": 1,
        "description": "The other issue's code."
      }
    },
    "required": [
      "relation",
      "issue"
    ],
    "additionalProperties": false
  }
}
```

Full document: https://docs.capy.ai/openapi.json