# Create issue (https://docs.capy.ai/api-reference/issues/create-issue)

`POST https://api.capy.ai/api/v1/issues`

## Authorization

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

## Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `projectId` | string | yes |  |
| `title` | string | yes |  |
| `description` | string | no |  |
| `stateId` | string | no | A state from `GET /issue-states`. Absent, the organization's default applies. |
| `priority` | `urgent` \| `high` \| `normal` \| `low` | no |  |
| `dueAt` | string | no |  |
| `assignees` | IssueAssigneeInput[] | no | The whole assignee set, primary first. An empty array leaves the issue unassigned. |
| `parent` | string | no | The parent issue's code, such as `CAP-12`. A sub-issue takes its parent's access. |
| `labelIds` | string[] | no | The whole label set, by id from `GET /issue-labels`. |
| `visibility` | `org` \| `private` | no | `org` for everyone in the project, `private` for the key's user and the issue's assignees. Absent, `org`. |
| `createdAt` | string | no | When the work item was first created, for an import. Absent, now; never in the future. |
| `updatedAt` | string | no | When the work item last changed, for an import. Absent, `createdAt`. |
| `files` | MessageFile[] | no |  |

## Responses

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

## Example

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

## 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_ProjectNotFoundEncoded": {
    "type": "object",
    "properties": {
      "_tag": {
        "type": "string",
        "enum": [
          "capy/ProjectNotFound"
        ]
      },
      "projectId": {
        "type": "string"
      }
    },
    "required": [
      "_tag",
      "projectId"
    ],
    "additionalProperties": false
  },
  "capy_FileNotFoundEncoded": {
    "type": "object",
    "properties": {
      "_tag": {
        "type": "string",
        "enum": [
          "capy/FileNotFound"
        ]
      },
      "fileId": {
        "type": "string"
      }
    },
    "required": [
      "_tag",
      "fileId"
    ],
    "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
  },
  "CreateIssueRequest": {
    "type": "object",
    "properties": {
      "projectId": {
        "type": "string"
      },
      "title": {
        "type": "string",
        "allOf": [
          {
            "minLength": 1
          },
          {
            "maxLength": 500
          }
        ]
      },
      "description": {
        "type": "string"
      },
      "stateId": {
        "type": "string",
        "description": "A state from `GET /issue-states`. Absent, the organization's default applies."
      },
      "priority": {
        "type": "string",
        "enum": [
          "urgent",
          "high",
          "normal",
          "low"
        ]
      },
      "dueAt": {
        "type": "string"
      },
      "assignees": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/IssueAssigneeInput"
        },
        "maxItems": 10,
        "description": "The whole assignee set, primary first. An empty array leaves the issue unassigned."
      },
      "parent": {
        "type": "string",
        "description": "The parent issue's code, such as `CAP-12`. A sub-issue takes its parent's access."
      },
      "labelIds": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "maxItems": 20,
        "description": "The whole label set, by id from `GET /issue-labels`."
      },
      "visibility": {
        "type": "string",
        "enum": [
          "org",
          "private"
        ],
        "description": "`org` for everyone in the project, `private` for the key's user and the issue's assignees. Absent, `org`."
      },
      "createdAt": {
        "type": "string",
        "description": "When the work item was first created, for an import. Absent, now; never in the future."
      },
      "updatedAt": {
        "type": "string",
        "description": "When the work item last changed, for an import. Absent, `createdAt`."
      },
      "files": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/MessageFile"
        }
      }
    },
    "required": [
      "projectId",
      "title"
    ],
    "additionalProperties": false
  },
  "IssueAssigneeInput": {
    "type": "object",
    "properties": {
      "kind": {
        "type": "string",
        "enum": [
          "user",
          "thread"
        ]
      },
      "id": {
        "type": "string"
      }
    },
    "required": [
      "kind",
      "id"
    ],
    "additionalProperties": false
  },
  "MessageFile": {
    "type": "object",
    "properties": {
      "fileId": {
        "type": "string",
        "description": "The `fileId` `POST /files` returned. The file's bytes must already be uploaded."
      },
      "name": {
        "type": "string",
        "maxLength": 1024,
        "description": "The file name shown on the attachment."
      }
    },
    "required": [
      "fileId",
      "name"
    ],
    "additionalProperties": false
  }
}
```

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