---
title: "Replace a goal"
method: PUT
path: "/sites/{id}/goals/{goalId}"
tags: ["Sites"]
---

# Replace a goal

`PUT /sites/{id}/goals/{goalId}`

## Request

- Base URL: `https://statable.com/api/v1`
- URL: `https://statable.com/api/v1/sites/{id}/goals/{goalId}`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/statable/apis/statable-stats-api/docs/sites/:id/goals/:goalId/put.ts> (a function with typed inputs; its response is checked against the schema)

## Request body

- GoalRequest: A goal counts a page (`path`), a custom event (`event_name`), or scroll depth (`event_name` "engagement" with `scroll_depth`). It needs at least an `event_name` or a `path` — without either it would match every event. An empty `event_name`, or a `scroll_depth` on any other `event_name`, is refused with 400 `invalid_request`: neither can ever convert as meant.
  - `name` string, required
  - `path` string: URL path to match.
  - `operator` 'e' | 'b' | 'c' | 'r': e = equals, b = begins with, c = contains, r = regular expression. A regex is RE2 (no lookaround, no backreferences); one that does not compile is refused with 400 `invalid_request`.
  - `event_name` string: Match a custom event instead of a path.
  - `scroll_depth` integer: Percent scrolled. Only with `event_name` "engagement".

## Response `200`

The updated goal.

- Goal
  - `id` integer, required
  - `host_id` integer, required
  - `name` string, required
  - `path` string
  - `operator` string
  - `event_name` string
  - `scroll_depth` integer
  - `created_at` string, date-time
  - `updated_at` string, date-time

## Other responses

- `400`: `invalid_request` — the body or a field is not acceptable.
- `401`: Missing/malformed/invalid/revoked bearer token (`unauthorized`), or a key past its expiry (`key_expired`; the message names the expiry time).
- `403`: `insufficient_scope`, `key_not_scoped`, or `not_site_owner`.
- `404`: `write_disabled`, `unknown_site`, or `goal_not_found`.
- `409`: `goal_exists`.
- `429`: Hourly account (default 2000/h) or per-key (default 600/h) limit hit (`rate_limited`). Retry after the `Retry-After` seconds. The X-RateLimit-* headers report the window that tripped (account on an account limit).
- `500`: Unexpected server error (`internal`). Report it with the `request_id` from the body or the X-Request-ID header: it is what lets the exact log entry be found, and without it a 500 can only be matched by guessing at a time window.

---

[API](https://skmtc.dev/statable/apis/statable-stats-api.md) - [All operations](https://skmtc.dev/statable/apis/statable-stats-api/llms.txt) - [OpenAPI document](https://skmtc.dev/statable/apis/statable-stats-api/revisions/352b6d47c186?raw)
