# Link an error to an issue

Link an error to an existing Linear or Jira issue.

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

[[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 = "issue"
required = true
type = "string"
description = "The issue to link, as a Linear issue identifier such as `ENG-123`, a Jira work item key such as `PROJ-45`, or the issue's URL."

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

[[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 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 is already linked to that issue, and the existing link is returned."
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 `issue` attribute is missing or isn't a string, or an attribute is unknown. Also returned when no issue matches `issue`, the team has no matching integration, `integration_id` names none of them or a different tracker, the integration needs to be reauthorized, or the error's occurrences are no longer stored. `errors` says which."

[[response]]
status = 422
description = "Linear or Jira refused the request. `errors` opens with `The issue couldn't be linked:` 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

```shell
[label Link an issue]
curl --request POST \
  --url https://errors.betterstack.com/api/v4/applications/1234/errors/6f1c2b9a8e4d7f3012ab45cd/issues/link \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "issue": "ENG-123"
}'
```
