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

# API Action

> Configure the “API” action in SimplePearl and AdvancedPearl to fetch or update data during a live conversation.

<div className="block dark:hidden">
  <Frame>
    <div className="p-1">
      <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=87f619237518ab1bbae239aed8d846db" alt="Send Email action interface on light mode" className="rounded-[14px]" width="3822" height="2300" data-path="images/light_mode/action_api.jpg" />
    </div>
  </Frame>
</div>

<div className="hidden dark:block">
  <Frame>
    <div className="p-1">
      <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=11eb6dcc3c8c38ef19b2aee0321cffdc" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="3822" height="2300" data-path="images/dark_mode/action_api.jpg" />
    </div>
  </Frame>
</div>

Connecting your Pearl to external systems with **API calls** lets it pull or push data in real time while talking to a customer.

This guide covers :

1. How API Actions differ in **Simple Pearl** vs **Advanced Pearl**
2. Every field you can configure (method, URL, headers, body, credentials)
3. Output‑schema filtering & variable assignment
4. How to test your configuration before going live

***

## API Action Modes

<CardGroup cols={2}>
  <Card title="Simple Pearl" icon="subtitles" iconType="light">
    Use the **When to trigger the action** field to state the exact moment or condition that fires the API call.
  </Card>

  <Card title="Advanced Pearl" icon="diagram-subtask" iconType="light">
    Add an **API node** inside the conversation tree. As soon as the flow reaches that node, the request runs automatically—no trigger field needed.
  </Card>
</CardGroup>

<Info>
  **Pre‑Call API (AdvancedPearl only)**\
  You may run a request *before* the call starts—perfect for:

  * **Inbound**: look up the caller by phone number (auto‑captured variable)
  * **Outbound**: preload variables already stored on the lead\
    For details see the Outbound Lead Creation page.
</Info>

***

## Configuring an API Action

<Steps>
  <Step title="HTTP Method">
    Choose **GET**, **POST**, **PUT**, **DELETE**, or **PATCH** depending on the API’s requirements.\
    If your API requires another verb, [contact support](mailto:support@nlpearl.ai) to request it.

    <div className="block dark:hidden">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-url-type.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=ce23f9491303035680e2a8aaee3e8ff1" alt="Send Email action interface on light mode" className="rounded-[14px]" width="2986" height="680" data-path="images/light_mode/action_api-url-type.jpg" />
        </div>
      </Frame>
    </div>

    <div className="hidden dark:block">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-url-type.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=6af3f66cb2b3e31053ba2218dd3ab298" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="2986" height="680" data-path="images/dark_mode/action_api-url-type.jpg" />
        </div>
      </Frame>
    </div>
  </Step>

  <Step title="URL">
    Type the API endpoint URL.\
    Click **+** to insert a variable into the URL — you can use both **Pre-Call variables** (collected before the call starts) and **In-Call variables** (collected during the conversation).

    <div className="block dark:hidden">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-url.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=af5b09b2047e0667a5f01b577c76fe1d" alt="Send Email action interface on light mode" className="rounded-[14px]" width="2986" height="680" data-path="images/light_mode/action_api-url.jpg" />
        </div>
      </Frame>
    </div>

    <div className="hidden dark:block">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-url.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=f4e17f167af40d0d00833470e91f4183" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="2986" height="680" data-path="images/dark_mode/action_api-url.jpg" />
        </div>
      </Frame>
    </div>
  </Step>

  <Step title="Headers">
    Add any header required by the API, such as `Content-Type`, `Authorization`, etc.

    <div className="block dark:hidden">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-header.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=32efecd0ddc5d92bfad90a89bd4c1b8f" alt="Send Email action interface on light mode" className="rounded-[14px]" width="2986" height="680" data-path="images/light_mode/action_api-header.jpg" />
        </div>
      </Frame>
    </div>

    <div className="hidden dark:block">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-header.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=d8f152af73d46bb98ee1777b5d72ac65" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="2986" height="680" data-path="images/dark_mode/action_api-header.jpg" />
        </div>
      </Frame>
    </div>

    <Info>
      Header values are static. If you need a **dynamic authorization token**, configure an [OAuth2 Credential](/pages/api_action#oauth2-credentials) to automatically inject it into the header at runtime.
    </Info>
  </Step>

  <Step title="Body">
    Supply Key / Value pairs as required by the API.

    <div className="block dark:hidden">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-body.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=cb1fa7b6366ee9ec59203a4aab1e28ea" alt="Send Email action interface on light mode" className="rounded-[14px]" width="2986" height="680" data-path="images/light_mode/action_api-body.jpg" />
        </div>
      </Frame>
    </div>

    <div className="hidden dark:block">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-body.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=ff0ee952b02e4a5f1e8cb5d105ddd2c1" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="2986" height="680" data-path="images/dark_mode/action_api-body.jpg" />
        </div>
      </Frame>
    </div>

    Each **Value** field can be:

    * A variable
    * A Text (string literal)
    * A Whole Number (integer)
    * A Decimal Number (float or double)
    * A Boolean (true/false)
    * A Date & Time
    * A **Custom Template** (a mix of static text and variables)

    <div className="block dark:hidden">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-customvariable.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=1163589a0306f8776938e059d3f20781" alt="Send Email action interface on light mode" className="rounded-[14px]" width="1756" height="680" data-path="images/light_mode/action_api-customvariable.jpg" />
        </div>
      </Frame>
    </div>

    <div className="hidden dark:block">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-customvariable.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=c3b187c7ad72a35aaa0b60d00c9b8ca9" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="1756" height="680" data-path="images/dark_mode/action_api-customvariable.jpg" />
        </div>
      </Frame>
    </div>

    <Info>
      For each variable, you can toggle a **"Required" checkbox**:

      * If checked, Pearl will automatically prompt the customer to provide the variable’s value before sending the API request, if it hasn’t been collected yet.
      * If unchecked, the API request will still be sent even if the variable is missing. In that case, the variable will simply be omitted from the request body.
    </Info>

    When using a variable in the body, be aware that:

    * The platform will **cast the variable to the corresponding data type** when sending the request.
    * For example, a variable of type **Whole Number** will be sent as an integer, while a **Text** variable will be quoted as a string.
    * If the variable type doesn’t match what the API expects, the API might reject the request or throw an error.

    You can mix static values and variables in the same request body to create dynamic payloads.

    <Info>
      If the API expects a nested JSON object, you can use **dot notation** in the Key to define nested paths (e.g., `customer.address.street`).
      Arrays can be represented using square brackets with an index (e.g., `order.items[0].productId`). see bellow Nested objects.
    </Info>
  </Step>
</Steps>

***

<Note>
  Additional notes

  * You can configure different API Actions inside the same Pearl if your flow needs multiple calls.
  * Every API Action can use a different set of variables, headers, and credentials.
  * You can use variables in **URL**, and **Body** to pass dynamic data collected during the call.
</Note>

***

### Using Nested Objects in API Actions

Many APIs expect a **nested JSON structure** in their request body.\
You can map variables to **nested keys** so your payload remains well organised and readable.

<Card title="How to define nested keys">
  * Use **dot notation** for properties  (`customer.address.street`)
  * Use **square brackets** for array indices  (`order.items[0].productId`)

  <Info>
    You can pair nested paths with any variable type—Text, Number, Boolean, etc.
  </Info>

  <Card>
    ### Example

    Variables collected:

    <ParamField path="customerName" type="text" />

    <ParamField path="customerEmail" type="text" />

    <ParamField path="street" type="text" />

    <ParamField path="city" type="text" />

    <ParamField path="productId" type="text" />

    <ParamField path="quantity" type="number" />

    Desired API body:

    ```json body.json theme={null}
    {
      "customer": {
        "name": "{{customerName}}",
        "email": "{{customerEmail}}",
        "address": {
          "street": "{{street}}",
          "city": "{{city}}"
        }
      },
      "order": {
        "items": [
          {
            "productId": "{{productId}}",
            "quantity": "{{quantity}}"
          }
        ]
      }
    }
    ```

    ***

    Mapping table:

    | API key                    | Variable        |
    | -------------------------- | --------------- |
    | `customer.name`            | `customerName`  |
    | `customer.email`           | `customerEmail` |
    | `customer.address.street`  | `street`        |
    | `customer.address.city`    | `city`          |
    | `order.items[0].productId` | `productId`     |
    | `order.items[0].quantity`  | `quantity`      |

    <Info>
      If the body contains deeper nesting or arrays, this mapping guarantees every variable lands at the correct path.
    </Info>
  </Card>
</Card>

***

## OAuth2 Credentials

If your API requires OAuth2 authentication, you’ll need to create a **Credential** on the platform to automatically manage token retrieval and injection.

This allows the platform to securely fetch an access token and automatically insert it into your API request headers.

<div className="block dark:hidden">
  <Frame>
    <div className="p-1">
      <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-credentials.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=36f7b84f1eda2c1c26e0970f9d9cc77c" alt="Send Email action interface on light mode" className="rounded-[14px]" width="3822" height="2300" data-path="images/light_mode/action_api-credentials.jpg" />
    </div>
  </Frame>
</div>

<div className="hidden dark:block">
  <Frame>
    <div className="p-1">
      <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-credentials.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=f4014a1df1f8de6d1bf5f0948218f582" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="3822" height="2300" data-path="images/dark_mode/action_api-credentials.jpg" />
    </div>
  </Frame>
</div>

<Tip>
  Why use a Credential?

  * Avoid hardcoding tokens manually in every API action
  * Automatically refresh tokens based on TTL (time‑to‑live)
  * Centralized management if multiple API actions reuse the same token
  * No need to manually parse token responses — the platform extracts it for you
</Tip>

***

### How to configure a Credential

<Steps>
  <Step title="1. Create a Credential">
    Go to **Credentials → Add New**, choose a **Name** (a label to help you identify it later), and select **OAuth2** as the type.

    <div className="block dark:hidden">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-create-credential.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=6a957f3b8251f89c02e0198c9b411261" alt="Send Email action interface on light mode" className="rounded-[14px]" width="2986" height="680" data-path="images/light_mode/action_api-create-credential.jpg" />
        </div>
      </Frame>
    </div>

    <div className="hidden dark:block">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-create-credential.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=aa1e7bdf8dbdd9048dba97f68d19f6ef" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="2986" height="680" data-path="images/dark_mode/action_api-create-credential.jpg" />
        </div>
      </Frame>
    </div>
  </Step>

  <Step title="2. Fill Credential Details">
    You’ll be asked to provide:

    * **Access Token URL**: the API endpoint to request the token

    <div className="block dark:hidden">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-access-token-url.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=bc539db2a9b8f8a5606aeaa5b68e2f65" alt="Send Email action interface on light mode" className="rounded-[14px]" width="2986" height="680" data-path="images/light_mode/action_api-access-token-url.jpg" />
        </div>
      </Frame>
    </div>

    <div className="hidden dark:block">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-access-token-url.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=f2049d282a4833ced5f2bea3645e46ea" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="2986" height="680" data-path="images/dark_mode/action_api-access-token-url.jpg" />
        </div>
      </Frame>
    </div>

    * Optional **headers** (e.g. `Content-Type: application/json`) for the token request
    * Optional **body** parameters (e.g. `grant_type`, `client_id`, `client_secret`)

    <div className="block dark:hidden">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-auth-head-body.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=641b50131deb8a770aa3fbafedd4d8ff" alt="Send Email action interface on light mode" className="rounded-[14px]" width="2986" height="1850" data-path="images/light_mode/action_api-auth-head-body.jpg" />
        </div>
      </Frame>
    </div>

    <div className="hidden dark:block">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-auth-head-body.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=ab52fcdd5274a8487ed3878a1443c1cb" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="2986" height="1850" data-path="images/dark_mode/action_api-auth-head-body.jpg" />
        </div>
      </Frame>
    </div>

    * **Token Config**:
      * `token path`: JSONPath to locate the token in the API response (e.g. "response.access\_token")
      * `ttl`: time‑to‑live for the token (default **300 seconds**; adjust if needed)
      * `header key`: name of the header where the token will be injected (e.g. `Authorization`)
      * `header prefix`: optional prefix for the token (e.g. `Bearer` or `Basic`)

    <div className="block dark:hidden">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/5m7CLiudjrqxiyho/images/light_mode/action_api-token-config.jpg?fit=max&auto=format&n=5m7CLiudjrqxiyho&q=85&s=d47cb24d657af4521aec06a40c26e930" alt="Send Email action interface on light mode" className="rounded-[14px]" width="2868" height="1066" data-path="images/light_mode/action_api-token-config.jpg" />
        </div>
      </Frame>
    </div>

    <div className="hidden dark:block">
      <Frame>
        <div className="p-1">
          <img src="https://mintcdn.com/nlpearl/ek92yQlpTyrjmvSe/images/dark_mode/action_api-token-config.jpg?fit=max&auto=format&n=ek92yQlpTyrjmvSe&q=85&s=c5ecb56a0b55ce5f248b2d8a578bdd34" alt="Send Email action interface on dark mode" className="rounded-[14px]" width="2868" height="1066" data-path="images/dark_mode/action_api-token-config.jpg" />
        </div>
      </Frame>
    </div>
  </Step>

  <Step title="3. Test Credential">
    Use the **Test Credential** button to send a request to the token endpoint and preview the JSON response.
    This test confirms that your configuration retrieves the token successfully.
  </Step>
</Steps>

<Card icon="circle-info" iconType="light">
  ### How the Credential is used in API actions

  Once saved, you can select this Credential from the **Credential** dropdown in any API Action.

  When selected:

  * The platform automatically adds the token to the API request header, using the configured `header key` and optional `header prefix`.
  * The token is refreshed automatically when expired, based on the configured `ttl`.

  <Info>
    If you don’t need authentication, simply leave the Credential toggle off.
  </Info>

  <Warning>
    Make sure the `token path` you enter corresponds to the exact location of the token in the JSON response.\
    If the platform can’t find the token at this path, the Credential will fail.
  </Warning>
</Card>

***

## Output Schema & Variable Assignment

<Warning>
  API responses are capped at **10 000 characters**. Anything longer is automatically truncated.
</Warning>

When using API actions, it’s crucial to control what part of the response is passed back into the conversation. That’s where the **Output Schema** comes in: it lets you filter the API response so only specific data is kept.

Without filtering, the entire JSON is returned — including irrelevant or unnecessary data. This can reduce the precision of the conversation, because the AI receives too much unrelated information.

Even if your API response is well under **10 000 characters**, we strongly recommend setting an Output Schema to focus the conversation on relevant data.

***

### How it works

* Provide a list of **JSONPath strings**.
* The system extracts only those paths from the API response.
* Everything else is discarded.

<Check>
  Benefits:

  * Keeps the response size small
  * Improves the quality and relevance of AI outputs
  * Prevents hitting the 10 000-character truncation limit
  * Ensures that only the necessary fields are carried into the next steps of the conversation
</Check>

<Card icon="circle-info" iconType="light">
  ### Assigning to a variable (optional)

  You can assign the value from a JSONPath directly to a variable.

  Key things to know:

  * **The variable’s type must match the data type returned by the API at that path.**
  * If the value returned is a list, make sure the variable is configured to **allow multiple values.**
  * A variable can store up to **600 characters.** Any data beyond this limit will be **truncated.**

  <Info>
    Assigning a variable is optional.\
    If you don’t assign a variable, the filtered JSON is still available for the conversation’s internal logic but may not be stored under a variable it should be if it is not obvious.
  </Info>

  In many cases, assigning variables helps later actions reuse that data (e.g. using a customer’s name in a message, or passing an ID into another API call).
</Card>

***

<Card icon="triangle-exclamation" iconType="light">
  ### Why Output Schema is critical

  <Card icon="x" iconType="light">
    Without an Output Schema:

    * The conversation may receive **unnecessary data**, lowering the accuracy of Pearl.
    * You risk hitting the **10 000-character response cap** and losing critical data.
    * This is the best way to map data directly to variables.
  </Card>

  <Card icon="check" iconType="light">
    By setting an Output Schema:

    * You control what gets passed into the conversation logic
    * You improve Pearl decision‑making by focusing on relevant fields
    * You unlock the ability to assign variables with safe and predictable data
  </Card>

  <Warning>
    Remember: if you assign to a variable, and the returned data exceeds **600 characters**, the variable’s value will be **cut off**.
  </Warning>
</Card>

***

## Testing Your API Action

<Steps>
  <Step title="Assign Test Values">
    Give sample values to every variable used in the request.
  </Step>

  <Step title="Run Test API">
    Click **Test API** to send the call.
  </Step>

  <Step title="Inspect">
    * Raw response
    * Filtered response (if you set an Output Schema)
    * Any variables populated from the response
  </Step>
</Steps>

<Tip>
  Use this tool to debug and perfect your setup before you put the Pearl in production.
</Tip>

***

<CardGroup cols={1}>
  <Card title="Variables" icon="square-root-variable" iconType="light" href="/pages/variables">
    Learn how to create and use variables inside API actions.
  </Card>
</CardGroup>

***

*Last updated: May 6, 2025*
