# Add an app action to a bot

`POST https://api.whatsable.app/v1/ai-bots/{id}/actions`

Required scope: `ai:configure`.

Adds an action of a connected app to this bot: the inputs you choose in `fixed`, and the inputs the bot fills from the conversation in `agent_inputs`. The app's action is read when you send this, and the setup must fit it. Connecting an app account is done in the dashboard, because the app's sign-in runs in a browser.

## Authorization

`Authorization: Bearer <API key>` (HTTP bearer, `bearerAuth`). The key looks like `nfy_live_<32 characters>`. An API key from Settings > API keys, sent as `Authorization: Bearer <key>`.

## Parameters

- `id` (path) string, required. The bot id. At most 64 characters.
- `Idempotency-Key` (header) string, optional. Any string up to 255 characters. A repeat with the same key and body answers the stored response; with another body, `409 idempotency_key_reused`. At most 255 characters.

## Request body

`application/json`, required.

- `name` string, required. At most 60 characters.
- `description` string, required. When the bot runs the action. The bot reads it. At most 500 characters.
- `read_only` boolean, optional. A lookup: the action only reads, and the bot may run it before it replies. Default `false`.
- `app` string, required. The app, as `GET /v1/app-connections` names it. At most 100 characters.
- `account_id` string, required. A connected account of that app. At most 64 characters.
- `component_key` string, required. The app's action, for example `google_calendar-create-event`. At most 200 characters.
- `fixed` object, optional. The inputs you choose, by input name, each `{ "value": ..., "label": "..." }`. `label` is optional: what the value is called in the app. Default `{}`.
- `agent_inputs` array of string, optional. The inputs the bot fills from the conversation, at most 10. Every required input of the action is either in `fixed` or here; an optional input in neither keeps the app's default. At most 10 items. Default `[]`.

## Responses

### 201

The action, granted to the bot.

- `object` `"ai_bot_action"`, required.
- `id` string, required. At most 64 characters.
- `name` string, required.
- `description` string, required. What the action does and when the bot runs it. The bot reads it.
- `method` string or null, required. The HTTP method. Null for an app action. One of: `"GET"`, `"POST"`, `"PUT"`, `"PATCH"`. New values may appear within v1.
- `url_host` string or null, required. The host the action calls. The path and the query are not shown: a webhook URL often carries its secret in them. Null for an app action.
- `inputs` array of object, required. The values the bot fills in when it runs the action.
  - `name` string, required.
  - `type` string, required. One of: `"string"`, `"number"`, `"integer"`, `"boolean"`, `"string_array"`. New values may appear within v1.
  - `description` string or null, required.
  - `required` boolean, required.
- `has_auth_secret` boolean, required. Whether a credential is sent with each call. The credential itself is never returned.
- `kind` string, required. `http_request`: a request to a URL, set up in the bot editor. `app_action`: an action of an app the organization connected. One of: `"http_request"`, `"app_action"`. New values may appear within v1.
- `read_only` boolean, required. A lookup: the action only reads, and the bot may run it before it writes its reply.
- `app_action` object or null, required. The app setup. Null for an HTTP action.
  - `app` string, required. The app, as Pipedream names it, for example `google_calendar`.
  - `account_id` string, required. The connected account the action runs as. See `GET /v1/app-connections`.
  - `component_key` string, required. The app's action, for example `google_calendar-create-event`.
  - `fixed` array of object, required. The inputs the organization chose. Every other input in `inputs` is the bot's to fill.
    - `name` string, required.
    - `value` any, required. The value, as the app takes it.
    - `label` string or null, required. What the value is called in the app, when the value is an id.
- `created_at` string (date-time), required.
- `updated_at` string (date-time), required.

### 400

invalid_request: `validation_failed`.

Body: the error body, under "Error body" below.

### 401

authentication: `api_key_in_wrong_place`, `api_key_missing`, `invalid_access_token`, `invalid_api_key`, `legacy_api_key_not_accepted`.

Body: the error body, under "Error body" below.

### 403

permission: `feature_not_in_plan`, `insufficient_scope`, `plan_inactive`.

Body: the error body, under "Error body" below.

### 404

not_found: `ai_bot_not_found`, `app_connection_not_found`.

Body: the error body, under "Error body" below.

### 409

conflict: `idempotency_key_reused`, `idempotency_request_in_progress`.

Body: the error body, under "Error body" below.

### 422

unprocessable: `ai_bot_action_limit_reached`, `ai_bot_action_setup_invalid`.

Body: the error body, under "Error body" below.

### 429

rate_limit: `rate_limited`.

Body: the error body, under "Error body" below.

### 500

internal: `internal_error`.

Body: the error body, under "Error body" below.

### 503

unavailable: `apps_not_available`, `service_unavailable`.

Body: the error body, under "Error body" below.

### Error body

Every 4xx and 5xx response above has this body.

- `error` object, required.
  - `type` string, required. The class of the error. Each type has exactly one HTTP status, such as `invalid_request` for 400. One of: `"invalid_request"`, `"authentication"`, `"permission"`, `"not_found"`, `"conflict"`, `"precondition_failed"`, `"unprocessable"`, `"rate_limit"`, `"internal"`, `"unavailable"`.
  - `code` string, required. The stable code a program branches on. Open: new codes are added under an existing status. One of: `"validation_failed"`, `"invalid_address"`, `"template_variable_missing"`, `"invalid_cursor"`, `"from_conflicts_with_conversation"`, `"media_too_large"`, `"media_type_unsupported"`, `"api_key_missing"`, `"invalid_api_key"`, `"api_key_in_wrong_place"`, `"legacy_api_key_not_accepted"`, `"invalid_access_token"`, `"insufficient_scope"`, `"number_not_allowed_for_key"`, `"plan_inactive"`, `"feature_not_in_plan"`, `"organization_not_live"`, `"number_over_plan"`, `"number_not_found"`, `"template_not_found"`, `"contact_not_found"`, `"conversation_not_found"`, `"message_not_found"`, `"label_not_found"`, `"media_not_found"`, `"route_not_found"`, `"scheduled_message_not_found"`, `"broadcast_not_found"`, `"ai_bot_not_found"`, `"knowledge_file_not_found"`, `"ai_bot_file_not_found"`, `"conversation_note_not_found"`, `"contact_fact_not_found"`, `"ai_bot_action_not_found"`, `"app_connection_not_found"`, `"ai_bot_app_setup_not_found"`, `"idempotency_key_reused"`, `"idempotency_request_in_progress"`, `"template_name_conflict"`, `"template_waba_not_connected"`, `"template_used_by_broadcast"`, `"label_name_conflict"`, `"ai_bot_name_conflict"`, `"precondition_failed"`, `"session_window_closed"`, `"template_not_approved"`, `"template_wrong_waba"`, `"template_not_supported"`, `"template_rejected_by_meta"`, `"number_not_sending"`, `"contact_has_no_address"`, `"label_limit_reached"`, `"free_tier_limit"`, `"ai_bot_limit_reached"`, `"scheduled_message_not_pending"`, `"broadcast_not_cancellable"`, `"broadcast_not_pausable"`, `"broadcast_not_resumable"`, `"ai_bot_not_archived"`, `"ai_bot_archived"`, `"ai_bot_file_limit_reached"`, `"ai_bot_text_too_long"`, `"contact_memory_full"`, `"ai_bot_action_not_editable"`, `"ai_bot_action_setup_invalid"`, `"ai_bot_action_limit_reached"`, `"ai_bot_app_setup_invalid"`, `"ai_bot_app_setup_limit_reached"`, `"label_not_available_on_number"`, `"reply_target_not_quotable"`, `"message_has_no_figures"`, `"message_not_reactable"`, `"channel_window_closed"`, `"channel_not_supported"`, `"channel_account_ambiguous"`, `"channel_conflicts_with_conversation"`, `"username_ambiguous"`, `"rate_limited"`, `"internal_error"`, `"service_unavailable"`, `"apps_not_available"`. New values may appear within v1.
  - `title` string, required. A short summary for a person. Wording may change.
  - `message` string, required. What happened, for a person. Wording may change.
  - `how_to_fix` string, required. What to change so the request succeeds.
  - `param` string or null, required. The offending field in dotted path form (`template.variables.2`), or null.
  - `source` string, required. Who returned the error: `meta` (WhatsApp) or `whatsable`. One of: `"meta"`, `"whatsable"`.
  - `owner` string, required. Who must act: `caller` (change the request or the account), `whatsable`, or `meta`. One of: `"caller"`, `"whatsable"`, `"meta"`.
  - `retryable` boolean, required. Whether the same request may succeed later without a change.
  - `docs_url` string, required. The docs page for this code.
  - `details` object, required. Structured facts for this code, such as `required_scope` or `meta_code`. Empty when there are none.
  - `request_id` string, required. The `X-Request-Id` of this response. Quote it to support.
  - `plans_url` string, optional. The public page that explains the plans and their limits. Present only on `plan_inactive`, `feature_not_in_plan`, `free_tier_limit` and `number_over_plan`.

## Example request

```bash
curl -X POST 'https://api.whatsable.app/v1/ai-bots/{id}/actions' \
  -H 'Authorization: Bearer <API key>' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Book a meeting",
  "description": "Run when the customer agrees on a date and time for a meeting.",
  "app": "google_calendar",
  "account_id": "apn_kVh9AoD",
  "component_key": "google_calendar-create-event",
  "fixed": {
    "calendarId": {
      "value": "sales@example.com",
      "label": "Sales calendar"
    }
  },
  "agent_inputs": [
    "summary",
    "eventStartDate",
    "eventEndDate"
  ]
}'
```
