---
title: "Run a server function on the draft"
method: POST
path: "/websites/{websiteId}/functions/{name}/invoke"
tags: ["Server functions"]
---

# Run a server function on the draft

`POST /websites/{websiteId}/functions/{name}/invoke`

## Request

- Base URL: `https://api.cactal.ai/v1`
- URL: `https://api.cactal.ai/v1/websites/{websiteId}/functions/{name}/invoke`
- Auth: HTTP bearer

Runs one of the draft site's `http` server functions with the website's secrets and returns its result, exactly as page code on the draft would receive it. It makes the function's real outgoing requests. Counts toward the plan's monthly calls.

## Path parameters

- `websiteId` string, required
- `name` string, required: An `http` server function.

## Request body

- object
  - `payload` unknown

## Response `200`

The run id and the result: `{ ok: true, data }` or `{ ok: false, error }`.

- object
  - `runId` string, required
  - `result` union, required
    - object
      - `ok` true, required
      - `data` unknown, required
    - object
      - `ok` false, required
      - `error` object, required
        - `code` 'not_found' | 'function_error' | 'timeout' | 'limit_exceeded' | 'unavailable', required
        - `message` string, required

## Other responses

- `400`: Validation failed. The response `message` names the first invalid field.
- `401`: Missing, invalid, expired, or revoked API key.
- `403`: The authenticated principal lacks the required capability.
- `404`: The resource does not exist or is outside the principal’s access scope.
- `429`: Rate limit exceeded. Retry after the number of seconds in the `Retry-After` header.

---

[API](https://skmtc.dev/cactal/apis/cactal-api.md) · [All operations](https://skmtc.dev/cactal/apis/cactal-api/llms.txt) · [OpenAPI document](https://skmtc.dev/cactal/apis/cactal-api/revisions/9cd0fb5eacdd?raw)
