# Create a release

Registers a new release. A release registered at build time shows up in Better Stack immediately, before its first error arrives.

[endpoint]
base_url = "https://errors.betterstack.com"
path = "/api/v1/releases"
method = "POST"

[[body_param]]
name = "version"
description = "Release version or commit reference (e.g., `v1.2.3`)."
required = true
type = "string"

[[body_param]]
name = "applications"
description = "Array of application IDs to attach the release to. When omitted, the release is attached to every application that already reports this version, and nothing is registered when no application reports it yet. Omitting it is the typical choice when recording a deploy."
required = false
type = "array of integers"

[[body_param]]
name = "environment"
description = "Environment this release was deployed to (e.g., `production`). Pass an array to record multiple environments."
required = false
type = "string"

[[body_param]]
name = "team_name"
description = "Scopes the registration to one team's applications when using [global API token](https://betterstack.com/docs/errors/api/getting-api-token/#get-a-global-api-token), which spans all your teams."
required = false
type = "string"

[[body_param]]
name = "team_id"
description = "The `SENTRY_ORG` value, which the Sentry CLI integration forwards, or the team ID shown in Better Stack URLs, like `t123`. Scopes the registration the same way as `team_name`. Prefer `team_name` when you call this endpoint directly."
required = false
type = "string"

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

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

[responses]
[[response]]
status = 201
description = '''Returns the registered release. The `releases` array lists the affected release IDs, one per application. An empty array means no application matched the version and nothing was recorded.'''
body = '''{
  "version": "v1.2.3",
  "applications": [123],
  "environment": "production",
  "releases": [
    {
      "id": 456,
      "application_id": 123
    }
  ]
}'''

[[response]]
status = 401
description = '''Unauthorized'''
body = '''{
  "errors": "Invalid authentication"
}'''

[[response]]
status = 422
description = '''Unprocessable Entity - Missing Required Attributes'''
body = '''{
  "errors": "Sorry, you are missing some required attributes",
  "required_attributes": ["version"]
}'''

[[response]]
status = 422
description = '''Unprocessable Entity - Unknown Application'''
body = '''{
  "errors": "Sorry, some values are incorrect",
  "invalid_values": {
    "applications": "Unknown applications: 999"
  }
}'''

[[response]]
status = 422
description = '''Unprocessable Entity - Unknown Team. The ID in your browser URL is rejected here even though it names your team, so pass the `SENTRY_ORG` value instead.'''
body = '''{
  "errors": "Sorry, some values are incorrect",
  "invalid_values": {
    "team_id": "Unknown team: 123456"
  }
}'''
[/responses]

#### Example cURL

```shell
[label Example]
curl --request POST \
  --url https://errors.betterstack.com/api/v1/releases \
  --header "Authorization: Bearer $TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{
    "version": "v1.2.3",
    "applications": [123],
    "environment": "production"
  }'
```

[warning]
#### Registering a brand new version?
Pass `applications`. Without it, Better Stack only attaches the environment to applications that already report the version, so a version nothing has reported yet returns `201` with an empty `releases` array and records nothing. Fail your CI step when `releases` comes back empty.
[/warning]
