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

# Set pre-call gate for agent

> Set an owned Nixflex agent's default pre-call gate. Number-specific settings can override this default for individual numbers.

**FIXED · organisation** **MUST** With organisations enabled, each organisation has one signing secret. Send the human Owner to the dashboard. Never ask for it in chat or expose it to AI tools.\
An authorised server can use an Owner session or the organisation API credential. Admin and Member sessions cannot retrieve it. Store it on the receiving server. Without organisations, the webhook signing secret is only the owning credential’s `KEY_SECRET` part. In either mode pass the webhook signing secret as `keySecret` to the Node verifier.

**NOT OFFERED → do this instead · number** call.bookings has no account field or per-number secret. After signature verification, look up number in your own tenant table. It is the business to number inbound and from number outbound.

**YOU CAN CHANGE · number** Set delivery destinations per number. Pre-call settings can be scoped to an agent or number. Keep the delivery destination and your signature-verification secret separate.

**SCOPE · operation** Verify X-Nixflex-Signature (`t=<timestamp>,v1=<hex>`) with HMAC-SHA256 over timestamp + "." + the original raw request body. Compare the digest in constant time and enforce a freshness policy before trusting the payload.

[Read the compact AI rules](https://docs.nixflex.com/ai-rules.md#webhooks)

Set the pre-call gate setting for an owned agent. This is the default for numbers on the agent; a number-specific gate takes precedence.

Method: **PUT** · Success: **200** · Scope: **Owning account**

**The important part**

* Save the setting for the exact owned target, then read it back to confirm.
* The five-second pre-call hook is fail-open; it is not a guaranteed call-blocking control.

[Business guide](https://docs.nixflex.com/guides/business/integrations.md) · [Developer guide](https://docs.nixflex.com/advanced/precall-gate.md) · [Glossary](https://docs.nixflex.com/guides/glossary.md)

## Authentication

Send `Authorization: Bearer KEY_ID:KEY_SECRET` using the owning account’s server-side credential. When personal dashboard sessions are enabled, Owner and Admin sessions can write these settings; Member sessions can read only. Ownership checks still apply. Send `Content-Type: application/json`.

## Request fields

| Field | Type | Required | Default | Limits and meaning |
| - | - | - | - | - |
| `agentId` (path) | string | Yes | None | Owned agent identifier. |

Send a JSON object.

| Field | Type | Required | Default | Limits and meaning |
| - | - | - | - | - |
| `url` | string | Yes | None | HTTPS destination. The handler trims the value and requires the https\:// prefix. |

GET shows only the URL at this level. An unset number URL can still inherit the agent gate. This settings endpoint does not invoke the gate or validate its response.

## Response fields

`200 OK` returns the shape below. Nullable fields can be unknown or unset; do not turn null into zero or false.

| Field | Type | Meaning |
| - | - | - |
| `ok` | boolean | Request succeeded. Value: `true`. |
| `agent_id` | string | Owned agent identifier. |
| `provider` | string | Integration identifier. Value: `"precall"`. |

## Example request

Examples require Node/CLI 0.11.0 or later, Python 0.4.0 or later and MCP 0.5.0 or later. Keep `NIXFLEX_API_KEY` in your private process environment. The cURL example uses Bash. Use approved owned fixtures and keep configuration responses private. Python shows sync usage; AsyncNixflex uses the same method with async with and await. Configure the existing MCP installation for the same account at `https://api.nixflex.com`. Save the request JSON fields from the example below in request-43.json privately before using cURL or CLI; replace fixture credentials only in that private file. Review the target and payload before this write.

```json request-43.json theme={"dark"}
{
  "url": "https://example.invalid/agent-gate"
}
```

```bash cURL theme={"dark"}
curl --request PUT \
  --url "https://api.nixflex.com/v1/integrations/precall/agent/agent%2Fexample" \
  --header "Authorization: Bearer $NIXFLEX_API_KEY" \
  --header "Content-Type: application/json" \
  --data-binary @request-43.json
```

```javascript Node theme={"dark"}
import Nixflex from 'nixflex';
const c = new Nixflex({apiKey:process.env.NIXFLEX_API_KEY,baseUrl:'https://api.nixflex.com',maxRetries:0});
const result = await c.integrations.setAgentPrecall("agent/example", "https://example.invalid/agent-gate");
// Keep private responses out of logs and AI conversations.
```

```python Python theme={"dark"}
import os
from nixflex import Nixflex
with Nixflex(api_key=os.environ["NIXFLEX_API_KEY"], base_url="https://api.nixflex.com", max_retries=0) as c:
    result = c.integrations.set_agent_precall('agent/example', 'https://example.invalid/agent-gate')
```

```powershell CLI (PowerShell) theme={"dark"}
# Save the documented JSON fields privately as request-43.json first.
nixflex integrations setAgentPrecall agent/example --body '@request-43.json' --confirm --json --base-url "https://api.nixflex.com"
```

MCP does not offer this operation because it accepts private credentials or executable settings; use the API, Node, CLI or Python.

## Example response

Illustrative `200` response. Identifiers and values are examples; some optional or compatibility fields are omitted.

```json Response theme={"dark"}
{
  "ok": true,
  "agent_id": "example-agent",
  "provider": "precall"
}
```

## Errors

Failures return an `error` object with `code`, `message`, `doc_url` and optional details. Each code links to the shared error catalog. Read the message and details before deciding whether to resend.

| Status | Code | Meaning | What to do |
| - | - | - | - |
| 404 | [`not_found`](https://docs.nixflex.com/api-reference/errors#not_found) | No matching owned resource or saved configuration was found. | Check the identifier and owning account. |
| 500 | [`server_error`](https://docs.nixflex.com/api-reference/errors#server_error) | The result could not be confirmed. | Read the current state before retrying a write. |
| 400 | [`missing_field`](https://docs.nixflex.com/api-reference/errors#missing_field) | A required field is missing or has the wrong type. | Correct the request before retrying. |
| 400 | [`invalid_url`](https://docs.nixflex.com/api-reference/errors#invalid_url) | The destination URL is not accepted. | Use the required HTTPS destination. |
| 400 | [`invalid_json`](https://docs.nixflex.com/api-reference/errors#invalid_json) | The JSON body could not be parsed. | Correct the request before retrying. |
| 413 | [`payload_too_large`](https://docs.nixflex.com/api-reference/errors#payload_too_large) | The request body is too large. | Reduce the request body. |
| 401 | [`unauthorized`](https://docs.nixflex.com/api-reference/errors#unauthorized) | The credential is missing or invalid. | Check the full account credential. |
| 429 | [`rate_limit_exceeded`](https://docs.nixflex.com/api-reference/errors#rate_limit_exceeded) | The account request limit was reached. | Wait for Retry-After. Reconcile uncertain writes before resending. |

## Retry and idempotency

The operation writes one saved setting and has no idempotency token. Read the current value after an uncertain response. Repeating it can overwrite a newer change, so reconcile before resending.

## Related endpoints

* [Get pre-call gate for number](https://docs.nixflex.com/api-reference/integration-settings/get-integrations-precall-number-phoneNumber.md)
* [Get pre-call gate for agent](https://docs.nixflex.com/api-reference/integration-settings/get-integrations-precall-agent-agentId.md)
* [Errors and recovery](https://docs.nixflex.com/api-reference/errors.md#error-envelope)


## OpenAPI

````yaml api-reference/public.openapi.json PUT /integrations/precall/agent/{agentId}
openapi: 3.1.0
info:
  title: Nixflex public API
  version: 1.0.0
  description: >-
    Nixflex API reference for agents, calls, messaging, knowledge, organisations
    and integrations. Authenticate with the owning account and follow each
    operation’s permissions, response and retry contract.
servers:
  - url: https://api.nixflex.com/v1
security:
  - bearerAuth: []
paths:
  /integrations/precall/agent/{agentId}:
    put:
      tags:
        - Integration settings
      summary: Set pre-call gate for agent
      description: >-
        Set the pre-call gate setting for an owned agent. This is the default
        for numbers on the agent; a number-specific gate takes precedence. GET
        shows only the URL at this level. An unset number URL can still inherit
        the agent gate. This settings endpoint does not invoke the gate or
        validate its response.
      operationId: setPrecallAgent
      parameters:
        - name: agentId
          in: path
          required: true
          schema:
            type: string
            description: Owned agent identifier.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                url:
                  type: string
                  description: >-
                    HTTPS destination. The handler trims the value and requires
                    the https:// prefix.
              required:
                - url
              additionalProperties: false
              description: ''
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    description: Request succeeded.
                    const: true
                  agent_id:
                    type: string
                    description: Owned agent identifier.
                  provider:
                    type: string
                    description: Integration identifier.
                    const: precall
                required:
                  - ok
                  - agent_id
                  - provider
                additionalProperties: false
                description: ''
              example:
                ok: true
                agent_id: example-agent
                provider: precall
        '400':
          description: >-
            missing_field: A required field is missing or has the wrong type.
            invalid_url: The destination URL is not accepted. invalid_json: The
            JSON body could not be parsed.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                        description: Error category.
                      code:
                        type: string
                        description: Machine-readable error code.
                      message:
                        type: string
                        description: Safe explanation.
                      doc_url:
                        type: string
                        description: Error documentation URL.
                      details:
                        type: object
                        additionalProperties: true
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    additionalProperties: false
                    description: ''
                required:
                  - error
                additionalProperties: false
                description: ''
        '401':
          description: 'unauthorized: The credential is missing or invalid.'
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                        description: Error category.
                      code:
                        type: string
                        description: Machine-readable error code.
                      message:
                        type: string
                        description: Safe explanation.
                      doc_url:
                        type: string
                        description: Error documentation URL.
                      details:
                        type: object
                        additionalProperties: true
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    additionalProperties: false
                    description: ''
                required:
                  - error
                additionalProperties: false
                description: ''
        '404':
          description: >-
            not_found: No matching owned resource or saved configuration was
            found.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                        description: Error category.
                      code:
                        type: string
                        description: Machine-readable error code.
                      message:
                        type: string
                        description: Safe explanation.
                      doc_url:
                        type: string
                        description: Error documentation URL.
                      details:
                        type: object
                        additionalProperties: true
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    additionalProperties: false
                    description: ''
                required:
                  - error
                additionalProperties: false
                description: ''
        '413':
          description: 'payload_too_large: The request body is too large.'
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                        description: Error category.
                      code:
                        type: string
                        description: Machine-readable error code.
                      message:
                        type: string
                        description: Safe explanation.
                      doc_url:
                        type: string
                        description: Error documentation URL.
                      details:
                        type: object
                        additionalProperties: true
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    additionalProperties: false
                    description: ''
                required:
                  - error
                additionalProperties: false
                description: ''
        '429':
          description: 'rate_limit_exceeded: The account request limit was reached.'
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                        description: Error category.
                      code:
                        type: string
                        description: Machine-readable error code.
                      message:
                        type: string
                        description: Safe explanation.
                      doc_url:
                        type: string
                        description: Error documentation URL.
                      details:
                        type: object
                        additionalProperties: true
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    additionalProperties: false
                    description: ''
                required:
                  - error
                additionalProperties: false
                description: ''
        '500':
          description: 'server_error: The result could not be confirmed.'
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                        description: Error category.
                      code:
                        type: string
                        description: Machine-readable error code.
                      message:
                        type: string
                        description: Safe explanation.
                      doc_url:
                        type: string
                        description: Error documentation URL.
                      details:
                        type: object
                        additionalProperties: true
                    required:
                      - code
                      - message
                      - doc_url
                      - type
                    additionalProperties: false
                    description: ''
                required:
                  - error
                additionalProperties: false
                description: ''
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        KEY_ID:KEY_SECRET from the owning account. Keep it server-side. A
        verified personal dashboard Bearer session may be used where the
        operation documents role-based access.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.