> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openhermit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /api/actions/sync

> Sync detected actions from a page and receive configured agent prompts.

Called by `script.js` after scanning a page. Upserts detected actions into the database and returns any agent prompts you've configured — which the script then injects into the page DOM.

## Request

```bash theme={null}
POST https://openhermit.com/api/actions/sync
Content-Type: application/json
```

```json theme={null}
{
  "api_key": "YOUR_API_KEY",
  "page_url": "https://yoursite.com/contact",
  "page_title": "Contact Us",
  "actions": [
    {
      "type": "contact_form",
      "name": "Contact Form",
      "tool_name": "contact_form",
      "tool_description": "Send a message to the team via the contact form",
      "selector": "#contact-form",
      "fields": [
        { "name": "name", "type": "text", "required": true },
        { "name": "email", "type": "email", "required": true },
        { "name": "message", "type": "textarea", "required": false }
      ]
    }
  ]
}
```

## Response

```json theme={null}
{
  "success": true,
  "actions": [
    {
      "id": "uuid",
      "tool_name": "contact_form",
      "selector": "#contact-form",
      "before_prompt": "Please have name and email ready.",
      "success_prompt": "Form submitted. We reply within 24h.",
      "failure_prompt": "Try hello@example.com directly.",
      "next_action_url": "https://calendly.com/example/30min",
      "next_action_label": "Book a meeting"
    }
  ]
}
```

## Behaviour

* If an action with the same `tool_name` already exists for this website, it is **updated** (name, type, selector, description) — existing prompt configuration is **preserved**.
* If the action is new, it is **created** with no prompts (configure them in the dashboard).
* Sending an empty `actions` array is valid — it confirms the script is running on a page without forms.

## CORS

Accepts cross-origin requests (`Access-Control-Allow-Origin: *`).
