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

# API Request

> Make HTTP requests to external services and integrate with your existing systems

The API Request block allows your Phonely agent to communicate with external systems in real time. It enables your AI agent to send data to, or retrieve data from, third-party services while a call is in progress.

This is commonly used for tasks such as creating CRM records, checking availability, triggering webhooks, sending notifications, or syncing call data with internal systems.

<img src="https://mintcdn.com/phonely/_jdAgjaqfJdK0vDj/assets/making-an-api-request-in-phonely.gif?s=f61a236905090028ddaf9891748110b0" alt="Making An Api Request In Phonely Gi" width="1228" height="720" data-path="assets/making-an-api-request-in-phonely.gif" />

## How it Works

The API Request block acts as a bridge between Phonely and external applications.

You can use it to:

* Send caller data such as names, phone numbers, emails, or custom variables to another system
* Retrieve information like order status, appointment availability, or account details
* Trigger automations in tools like Zapier, Make, Slack, or internal APIs
* Execute webhooks during or after a call

Phonely supports standard REST APIs and allows you to configure requests either by importing a cURL command or building the request manually.

## How to Use it

In your Flow Editor, locate the block where the API call should occur, then click the ➕ (plus) icon.

To add an API Request block:

1. Open your Flow Editor.
2. Locate the point in the flow where the API interaction should occur.
3. Click the **➕ (plus)** icon beneath or beside an existing block.
4. Under **Actions**, select **API Request**.

A new block labeled **API Request** will appear on your canvas.

<img src="https://mintcdn.com/phonely/92-YWjeCySzQC5rN/assets/how-to-add-an-api-request-block.png?fit=max&auto=format&n=92-YWjeCySzQC5rN&q=85&s=a69d664475947797ffbcc6397cd9fdae" alt="How To Add An Api Request Block" title="How To Add An Api Request Block" style={{ width:"96%" }} width="3836" height="1688" data-path="assets/how-to-add-an-api-request-block.png" />

## Setup

When you open the block, you’ll see two ways to define your API request:

### Option 1: Import from cURL

If you already have a cURL command (for example, from Postman or API documentation):

1. Paste the full cURL command into the **cURL Command** field.
2. Click **Import from cURL**. Phonely automatically extracts the method, endpoint, headers, and body.

Example:

```text theme={null}
curl -X POST "https://jsonplaceholder.typicode.com/posts" \
-H "Content-Type: application/json" \
-d '{
  "title": "Phonely Flow Test",
  "body": "This is a test API request from my Phonely flow.",
  "userId": 1
}'
```

After import, Phonely converts this into structured fields in the configuration tab.

### Option 2: Build Manually

If you don’t have a cURL command, click **Build Manually**. You’ll then define all settings step by step in the **Configure** tab.

<img src="https://mintcdn.com/phonely/_jdAgjaqfJdK0vDj/assets/manually-build-api-request-flow.gif?s=2a7c3f3dc854dcd70590bfa2a0f7b4a5" alt="Manually Build Api Request Flow Gi" width="1228" height="720" data-path="assets/manually-build-api-request-flow.gif" />

## Configuration

The **Configure** tab is where you define what your API request should do.

<img src="https://mintcdn.com/phonely/eVENcZMjlZ9wdqjE/assets/configure-api-request-manually.png?fit=max&auto=format&n=eVENcZMjlZ9wdqjE&q=85&s=0d80f32ada938a2ccdaf8cfd115f137d" alt="Configure Api Request Manually" title="Configure Api Request Manually" style={{ width:"72%" }} width="2492" height="2268" data-path="assets/configure-api-request-manually.png" />

<Steps>
  <Step titleSize="h3" title="API Method">
    Select the type of request from the dropdown:

    * `GET` – Retrieve data from a system.
    * `POST` – Send new data.
    * `PUT` or `PATCH`– Update an existing record.
    * `DELETE` – Remove a resource.

    > Example: Choose **POST** when sending call data to an external app.
  </Step>

  <Step titleSize="h3" title="API URL">
    Enter the endpoint where the request should go. This is the destination for your data.
  </Step>

  <Step titleSize="h3" title="Headers">
    Headers define metadata or authentication details for your API call.                                                         Click **+ Add** to add key-value pairs such as:

    <img src="https://mintcdn.com/phonely/eVENcZMjlZ9wdqjE/assets/configure-header-for-api-request.png?fit=max&auto=format&n=eVENcZMjlZ9wdqjE&q=85&s=e1edbcc92560e0739e2c1e7b0c6bb4eb" alt="Configure Header For Api Request" title="Configure Header For Api Request" style={{ width:"96%" }} width="2392" height="756" data-path="assets/configure-header-for-api-request.png" />

    Select the type of request from the dropdown:

    * `GET` – Retrieve data from a system.
    * `POST` – Send new data (most common).
    * `PUT` or `PATCH` – Update an existing record.
    * `DELETE` – Remove a resource.

    > Example: Choose **POST** when sending call data to an external app.

    <Tip>
      Always include `Content-Type: application/json` for JSON-based APIs.
    </Tip>
  </Step>

  <Step titleSize="h3" title="Query Parameters">
    Use this if your API uses query strings in the URL (e.g., filtering or pagination).

    <img src="https://mintcdn.com/phonely/eVENcZMjlZ9wdqjE/assets/configure-query-parameters-in-phonely.png?fit=max&auto=format&n=eVENcZMjlZ9wdqjE&q=85&s=0a706dd76afdda01800e28bff4a8d96c" alt="Configure Query Parameters In Phonely" title="Configure Query Parameters In Phonely" style={{ width:"95%" }} width="2308" height="680" data-path="assets/configure-query-parameters-in-phonely.png" />
  </Step>

  <Step stepNumber={5} titleSize="h3" title="Body (For POST, PUT, PATCH Requests)">
    For **POST**, **PUT**, or **PATCH** requests, you can define a request body. Phonely supports multiple body types, selectable directly in the UI.

    Enter the endpoint where the request should go. This is the destination for your data.

    #### Supported Body Types

    **None**\
    Use this when the request does not require a body.

    Headers define metadata or authentication details for your API call. Click **+ Add** to add key-value pairs such as:

    **x-www-form-urlencoded**\
    Use this when the API expects traditional form data. Each key-value pair is sent as form data, commonly required by legacy systems or OAuth flows.

    <img src="https://mintcdn.com/phonely/E7CiyfSBryDgLxkE/assets/x-www-form-urlencoded.png?fit=max&auto=format&n=E7CiyfSBryDgLxkE&q=85&s=e3015b1da39f57ce50812fd646235c68" alt="X Www Form Urlencoded" width="2344" height="716" data-path="assets/x-www-form-urlencoded.png" />

    **JSON**\
    Use this when sending structured data in JSON format (most modern APIs).\
    You can switch the editor to **Code** mode to write raw JSON directly.

    <img src="https://mintcdn.com/phonely/J1SHiOdv0Kh5Te7B/assets/api-payload-config-page.png?fit=max&auto=format&n=J1SHiOdv0Kh5Te7B&q=85&s=86d176857d3bd94069a5345bf3ec7cfe" alt="Api Payload Config Page" title="Api Payload Config Page" style={{ width:"60%" }} width="2908" height="3192" data-path="assets/api-payload-config-page.png" />

    <Tip>
      You can make your API requests dynamic by inserting variables captured earlier in your flow. Type `@`to open the variable picker or select from available variables or auto-gather variables to include dynamic data in your request.
    </Tip>
  </Step>

  <Step stepNumber={6} title="Advanced settings">
    Click to expand this section. These options help control the flow behavior during API communication.

    Example:

    <img src="https://mintcdn.com/phonely/73M7QNvjsxFWSUTg/assets/api-request-block-advanced-settings.png?fit=max&auto=format&n=73M7QNvjsxFWSUTg&q=85&s=34726449aff1bc54adcf1d42a213b89c" alt="Api Request Block Advanced Settings" title="Api Request Block Advanced Settings" style={{ width:"61%" }} width="1912" height="1864" data-path="assets/api-request-block-advanced-settings.png" />

    | **Setting**                    | **Description**                                                                       |
    | :----------------------------- | :------------------------------------------------------------------------------------ |
    | **Enable Error Handling**      | Lets you catch failed API calls and redirect the flow.                                |
    | **Retry on Failure**           | Retries automatically if the server doesn’t respond.                                  |
    | **Interim Message**            | Sends a short message to the caller (e.g., “Please hold while I send your request.”). |
    | **Post Interim Message Delay** | Adds a short pause after the interim message.                                         |
    | **Call Outcome Tagging**       | Add labels for analytics or call reports (e.g., “api\_success” or “crm\_update”).     |

    Click **Continue** to save and move on to the **Test** step.
  </Step>
</Steps>

## Test Stage

Testing ensures your configuration works before you publish your flow.

1. Click **Test**.\
   Phonely will send the request exactly as you configured.
2. The response will display instantly, showing whether it succeeded or failed.

If successful, you’ll see:

```text theme={null}
Status: 201 Created
```

If failed, you’ll get an error message explaining what went wrong (e.g., invalid URL, authentication error, or timeout).

<Note>
  When building workflows, you can now hover over API request and code block variables to instantly preview test data. This reduces debugging time and improves confidence before publishing flows
</Note>

<img src="https://mintcdn.com/phonely/ROyEq1IIii0PKodQ/assets/preview-api-request-test-data.png?fit=max&auto=format&n=ROyEq1IIii0PKodQ&q=85&s=6a09b865428c2f5d169231be5e1d98c5" alt="Preview Api Request Test Data" title="Preview Api Request Test Data" style={{ width:"61%" }} width="3300" height="3048" data-path="assets/preview-api-request-test-data.png" />

## Use cases for API Requests

| **Scenario**    | **Action** | **Example Use Case**                            |
| :-------------- | :--------- | :---------------------------------------------- |
| CRM integration | POST       | Send collected lead data to HubSpot or Zoho CRM |
| SMS gateway     | POST       | Send a text message via Twilio                  |
| Data lookup     | GET        | Fetch an order status or product info           |
| Notification    | POST       | Trigger a Slack or Discord webhook              |
| Ticket creation | POST       | Create a support ticket in Zendesk or Freshdesk |
