# Setting up Call API Block in Flow

Call API Block provides automated HTTP callback functions that you can use to perform an API request by various methods, including GET, POST, PUT, DELETE etc.

<figure><img src="https://605198658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FP7nf2G1iCRba8EP7DawZ%2Fuploads%2FMFKozUtVjUXZwb0FMqzz%2Fimage.png?alt=media&#x26;token=78bdf600-f176-4152-a73c-e06b0073f3d5" alt=""><figcaption></figcaption></figure>

### URL & Method

Choose a Request method and enter your URL endpoint of the external API.

You can make your URL dynamic by inserting variables into the path. For the user input variable that you set up in the flow, for example, it is called "order\_num", you can call it with {{order\_num}}. For custom fields, for a field called "membership", you can call it {{customFields.membership}}.

### Customize Header

Headers in HTTP webhook requests are used to specify the purpose of the API or its content type.

It is optional to use headers. It is under Additional Settings and is turned off by default. Headers are set as key-value pairs.&#x20;

e.g. key = Content-Type & value = application/json

### Customize the Body

The body of the API request is added here. This is also optional and set as off by default. The body must always be in JSON format.

Formatting Tips:

* Strings and Variables must be wrapped in quotes > {{name}}
* A comma is needed between 2 key-value pairs > "Email": "{{email}}", "Name": "{{name}}"
* If the variable is a custom field but not a default field (i.e. name, email, phone), for example the field name is membership, the format should be > “{{customFields.membership}}“

### **Set your test variable**

Manually set your test variables by clicking "Add Variables".

### Test the Request

You can test the API request by clicking on the 'Test the request' button.

### Save Responses as Variables

You can also save the response of a request into variables or custom attributes. If your API response is a JSON with a key-value pair, you can store each of the values by passing the key name.&#x20;

**Storing Response Values that are Inside an Object:**

If you want to store the response value that is inside an object, you need to use the `objectkey.keyname` format.

Example: if you want to store the `userId`, you have to use `Result.userId` in the **"Entire response Body"** above

```
{ 
    "Result": { 
        "userId": "xxxxx", 
        "PhoneNumber": "xxxxxx", 
        "PurchaseHistory": null, 
    }
}
```

**Storing Responses that are Inside an Array of the Object:**

If you want to store the response value that is inside an Array of an object, you need to use the `[0].objectkey.keyname[0].value` format

Example: if you want to store `shipping_status`, you have to use `[0].order_tracking.shipment_track[0].shipping_status` in the **"Entire response Body"** above

```
[
    {
        "order_tracking": {
            "track_status":0,
            "shipment_track" : [
                {
                    "id":123342515,
                    "shipping_status":"On the way"
                }
            ]
        }
    }
]
```

### **Response Routing**

\
You can use response routing to split your flow according to response status codes. By default each Call API Block has "success" and "failed" node. You can optionally add custom status code as you need.\ <br>
