# Create an error issue

Create a Linear issue or Jira work item for an error, and link it. The issue describes the error with its call site, stack trace and a link to it in Better Stack, and uses the integration's default project and settings.

[endpoint]
method = "POST"
base_url = "https://errors.betterstack.com"
path = "/api/v4/applications/{application_id}/errors/{error_id}/issues"

[[path_param]]
name = "application_id"
required = true
type = "string"
description = "The ID of the application, from [List applications](/docs/errors/api/applications/list/)."

[[path_param]]
name = "error_id"
required = true
type = "string"
description = "The error's `id`, from [List errors](/docs/errors/api/errors/list/). Can contain dots."

[[body_param]]
name = "integration_id"
type = "string"
description = "The ID of the Linear or Jira integration to create the issue with. Needed only when your team has several. Leave it out then, and the request is refused with 422 and `integration_ids` lists them."

[[body_param]]
name = "title"
type = "string"
description = "The issue's title. Defaults to the application's name in brackets, then the error's type and message."

[[body_param]]
name = "notes"
type = "string"
description = "Text added at the top of the issue's description."

[[query_param]]
name = "team_id"
type = "string"
description = "Team to use, such as `t123`. Get the ID via [List teams](/docs/uptime/api/teams/list/). Required when you can access more than one team."

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"

[[header]]
name = "Content-Type"
description = "application/json"
required = false
type = "string"
[/endpoint]

[responses]
[[response]]
status = 201
description = "Returns the newly created error issue."
body = '''
{
  "data": {
    "id": "123456789",
    "type": "error_issue",
    "attributes": {
      "integration_id": "7",
      "integration_type": "linear",
      "external_id": "ENG-123",
      "label": "ENG-123",
      "url": "https://linear.app/example/issue/ENG-123",
      "operation": "linked_manually"
    }
  }
}
'''

[[response]]
status = 200
description = "Returns the error issue. Returned when the error already has an issue through that integration, and it's returned instead of creating another."
body = '''
{
  "data": {
    "id": "123456789",
    "type": "error_issue",
    "attributes": {
      "integration_id": "7",
      "integration_type": "linear",
      "external_id": "ENG-123",
      "label": "ENG-123",
      "url": "https://linear.app/example/issue/ENG-123",
      "operation": "linked_manually"
    }
  }
}
'''

[[response]]
status = 401
description = "The API token is missing or invalid."
body = '''
{
  "errors": "Invalid Team API token. How to find your Team API token: https://betterstack.com/docs/logs/api/getting-started/#obtaining-a-logtail-api-token"
}
'''

[[response]]
status = 403
description = "The token is read-only, or its scopes don't permit the action."
body = '''
{
  "errors": "This API token is read-only and cannot be used for write operations."
}
'''

[[response]]
status = 404
description = "No application with that ID, or no error with that ID in it."

[[response]]
status = 422
description = "Your team has more than one integration the issue could go through. `integration_ids` lists them. Pass one as `integration_id`."
body = '''
{
  "errors": "More than one integration could serve this request. Pass integration_id set to one of the listed IDs.",
  "integration_ids": [
    "7",
    "9"
  ]
}
'''

[[response]]
status = 422
description = "The team has no Linear or Jira integration, `integration_id` names none of them, the title is too long for Linear, the integration's setup isn't finished, it needs to be reauthorized, the error's occurrences are no longer stored, `title` or `notes` isn't a string, or an attribute is unknown. `errors` says which."

[[response]]
status = 422
description = "Linear or Jira refused to create the issue. `errors` opens with `The issue couldn't be created:` and gives the tracker's reason."

[[response]]
status = 503
description = "The integration couldn't be loaded, or Linear or Jira didn't respond because of an outage, a timeout or rate limiting. Try again in a few moments."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The ID of the error issue."

[[param]]
name = "type"
type = "string"
description = "Always `error_issue`."

[[param]]
name = "integration_id"
type = "string"
description = "The ID of the Linear or Jira integration the issue is linked through."

[[param]]
name = "integration_type"
type = "string"
description = "The tracker, such as `linear` or `jira`."

[[param]]
name = "external_id"
type = "string"
description = "The issue's ID in the tracker."

[[param]]
name = "label"
type = "string"
description = "The issue's identifier in the tracker, such as `ENG-123` or `PROJ-45`."

[[param]]
name = "url"
type = "string"
description = "Link to the issue in the tracker."

[[param]]
name = "operation"
type = "string"
description = "How the link was made.<br/>Valid values:<br/>`created_automatically`: The issue was created automatically for a new error.<br/>`created_manually`: The issue was created on request.<br/>`linked_manually`: An existing issue was linked."
[/params]

#### Example cURL

[code-tabs]
```shell
[label Create an issue]
curl --request POST \
  --url https://errors.betterstack.com/api/v4/applications/1234/errors/6f1c2b9a8e4d7f3012ab45cd/issues \
  --header "Authorization: Bearer $TOKEN"
```
```shell
[label With a title and notes]
curl --request POST \
  --url https://errors.betterstack.com/api/v4/applications/1234/errors/6f1c2b9a8e4d7f3012ab45cd/issues \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "title": "TypeError in renderCart",
  "notes": "Started after the 1.4.2 deploy."
}'
```
[/code-tabs]
