> ## 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.

# Create a custom function

> Create a custom function for an owned Nixflex number. Each number allows up to 15 functions with names unique within that number.

**FIXED · number** When website functions are enabled, eligible enabled functions on that number can be offered to visitors. A visitor ID groups a conversation and cannot authorise access to your own customer records.

**NOT OFFERED → do this instead · operation** Putting a new action tag like \[BOOK\_NOW] in a prompt does not create a function. Configure a number-scoped function with its argument schema, or use a supported phone booking integration.

**YOU CAN CHANGE · number** Choose a supported name, HTTPS destination and HTTP method. Keep credentials in trusted configuration and return only the response fields the agent needs.

**SCOPE · operation** A configured function can call your service with validated arguments. Make each public function safe for its intended audience.

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

Create one function for an owned number. Each number can have at most 15 functions; names must be unique for that number.

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

**The important part**

* Save the setting for the exact owned target, then read it back to confirm.
* Verify signed inputs before executing consequential work.

[Business guide](https://docs.nixflex.com/guides/business/integrations.md) · [Developer guide](https://docs.nixflex.com/advanced/custom-functions.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 |
| - | - | - | - | - |
| `phoneNumber` (path) | string | Yes | None | Owned E.164 number. URL-encode the leading plus sign. |

Send a JSON object.

| Field | Type | Required | Default | Limits and meaning |
| - | - | - | - | - |
| `name` | string | Yes | None | Lowercase snake\_case function name. Maximum 64 characters. Pattern: `^[a-z][a-z0-9_]*$`. |
| `description` | string | No | `""` | Description supplied to the agent. |
| `url` | string | Yes | None | HTTPS destination; required on create. |
| `method` | string | No | `"POST"` | Uppercased before validation. Allowed: `"GET"`, `"POST"`, `"PUT"`, `"PATCH"`, `"DELETE"`. |
| `headers` | object | No | `{}` | Private HTTP headers. GET returns only has\_headers. |
| `parameters` | object | No | `{"type":"object","properties":{}}` | Function parameter JSON schema. |
| `speak_during` | string or null | No | `null` | Optional phrase; a falsey value clears it. |
| `timeout_ms` | integer | No | `5000` | Parsed as an integer and clamped to 1,000–45,000 ms. Zero or nonnumeric values fall back to 5,000. |
| `is_active` | boolean | No | `true` | Only literal false disables the function. |

Headers are private and never returned by the list route. Timeout inputs are parsed and clamped; the stored range is 1,000–45,000 ms. A supplied falsey description becomes an empty string, falsey headers become an empty object, falsey parameters restore the default schema, and falsey speak\_during clears the phrase.

## 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`. |
| `id` | string | Function identifier. |
| `phone_number` | string | Owned phone number. |
| `name` | string | Saved function name. |

## 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-46.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-46.json theme={"dark"}
{
  "name": "lookup_fixture",
  "url": "https://example.invalid/tool",
  "method": "POST",
  "headers": {
    "X-Fixture": "private_fixture_value"
  },
  "parameters": {
    "type": "object",
    "properties": {}
  },
  "speak_during": null,
  "timeout_ms": 0,
  "is_active": false
}
```

```bash cURL theme={"dark"}
curl --request POST \
  --url "https://api.nixflex.com/v1/integrations/custom-functions/number/%2B12025550123" \
  --header "Authorization: Bearer $NIXFLEX_API_KEY" \
  --header "Content-Type: application/json" \
  --data-binary @request-46.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.createFunction("+12025550123", {"name": "lookup_fixture", "url": "https://example.invalid/tool", "method": "POST", "headers": {"X-Fixture": "private_fixture_value"}, "parameters": {"type": "object", "properties": {}}, "speak_during": null, "timeout_ms": 0, "is_active": false});
// 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.create_function('+12025550123', name='lookup_fixture', url='https://example.invalid/tool', method='POST', headers={'X-Fixture': 'private_fixture_value'}, parameters={'type': 'object', 'properties': {}}, speak_during=None, timeout_ms=0, is_active=False)
```

```powershell CLI (PowerShell) theme={"dark"}
# Save the documented JSON fields privately as request-46.json first.
nixflex integrations createFunction '+12025550123' --body '@request-46.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,
  "id": "11111111-1111-4111-8111-111111111111",
  "phone_number": "+12025550100",
  "name": "lookup_booking"
}
```

## 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 |
| - | - | - | - |
| 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 | [`invalid_phone`](https://docs.nixflex.com/api-reference/errors#invalid_phone) | The number is not valid E.164. | Correct the request before retrying. |
| 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. |
| 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_name`](https://docs.nixflex.com/api-reference/errors#invalid_name) | The function name is invalid. | Correct the request before retrying. |
| 400 | [`invalid_method`](https://docs.nixflex.com/api-reference/errors#invalid_method) | The HTTP method is not accepted. | Correct the request before retrying. |
| 409 | [`duplicate_function`](https://docs.nixflex.com/api-reference/errors#duplicate_function) | Another function on this number uses that name. | Correct the request before retrying. |
| 400 | [`limit_reached`](https://docs.nixflex.com/api-reference/errors#limit_reached) | The number already has 15 functions. | Remove an unused function before creating another. |
| 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

No idempotency token is supported. Read the function list after a timeout before resending. Creation can conflict with an existing name, and repeating a delete may remove a function recreated under the same ID.

## Related endpoints

* [List custom functions](https://docs.nixflex.com/api-reference/integration-settings/get-integrations-custom-functions-number-phoneNumber.md)
* [Update a custom function](https://docs.nixflex.com/api-reference/integration-settings/patch-integrations-custom-functions-number-phoneNumber-id.md)
* [Errors and recovery](https://docs.nixflex.com/api-reference/errors.md#error-envelope)


## OpenAPI

````yaml api-reference/public.openapi.json POST /integrations/custom-functions/number/{phoneNumber}
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/custom-functions/number/{phoneNumber}:
    post:
      tags:
        - Integration settings
      summary: Create a custom function
      description: >-
        Create one function for an owned number. Each number can have at most 15
        functions; names must be unique for that number. Headers are private and
        never returned by the list route. Timeout inputs are parsed and clamped;
        the stored range is 1,000–45,000 ms. A supplied falsey description
        becomes an empty string, falsey headers become an empty object, falsey
        parameters restore the default schema, and falsey speak_during clears
        the phrase.
      operationId: createCustomFunction
      parameters:
        - name: phoneNumber
          in: path
          required: true
          schema:
            type: string
            description: Owned E.164 number. URL-encode the leading plus sign.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: Lowercase snake_case function name.
                  pattern: ^[a-z][a-z0-9_]*$
                  maxLength: 64
                description:
                  type: string
                  description: Description supplied to the agent.
                  default: ''
                url:
                  type: string
                  description: HTTPS destination; required on create.
                method:
                  type: string
                  description: Uppercased before validation.
                  enum:
                    - GET
                    - POST
                    - PUT
                    - PATCH
                    - DELETE
                  default: POST
                headers:
                  type: object
                  additionalProperties: true
                  description: Private HTTP headers. GET returns only has_headers.
                  default: {}
                  writeOnly: true
                parameters:
                  type: object
                  additionalProperties: true
                  description: Function parameter JSON schema.
                  default:
                    type: object
                    properties: {}
                speak_during:
                  type:
                    - string
                    - 'null'
                  description: Optional phrase; a falsey value clears it.
                  default: null
                timeout_ms:
                  type: integer
                  description: >-
                    Parsed as an integer and clamped to 1,000–45,000 ms. Zero or
                    nonnumeric values fall back to 5,000.
                  default: 5000
                is_active:
                  type: boolean
                  description: Only literal false disables the function.
                  default: true
              required:
                - name
                - url
              additionalProperties: false
              description: ''
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                    description: Request succeeded.
                    const: true
                  id:
                    type: string
                    description: Function identifier.
                  phone_number:
                    type: string
                    description: Owned phone number.
                  name:
                    type: string
                    description: Saved function name.
                required:
                  - ok
                  - id
                  - phone_number
                  - name
                additionalProperties: false
                description: ''
              example:
                ok: true
                id: 11111111-1111-4111-8111-111111111111
                phone_number: '+12025550100'
                name: lookup_booking
        '400':
          description: >-
            invalid_phone: The number is not valid E.164. invalid_url: The
            destination URL is not accepted. invalid_name: The function name is
            invalid. invalid_method: The HTTP method is not accepted.
            limit_reached: The number already has 15 functions. 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: ''
        '409':
          description: 'duplicate_function: Another function on this number uses that name.'
          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.