---
description: >-
  This document explains the simplified ways to configure External APIs and
  create engagement.
---

# External API

External API facilitates you to connect with multiple third-party APIs allowing you to integrate with any third-party service like a CRM, IVR, Private ESP/SSP, etc. to automate your engagements.

## **Use cases for External API**

1. **CRM:** Integrate with CRM like Hubspot, Vymo, etc.
2. **IVR:** Integrate IVR services to automate communication for immediate responses&#x20;
3. **Private ESP/SSP:** Integrate your own email or SMS service providers to create engagement to ensure the confidentiality and privacy of your PII data through data encryption.
4. **Email Service Provider (ESP):** Integrate with email service providers like mailmodo, etc.
5. **Facebook Conversion API/ Google Conversion API**: Integrate Facebook and Google conversion API to send conversion data from CDP to Google and Facebook
6. **Internal system API:** Pass data from the CDP to internal APIs in services like Banking financial services and insurance which will have confidential APIs used internally for their service operations.
7. **Lead submission API:** Submit the data captured from WhatsApp or any other lead forms into your lead management system&#x20;

## **Prerequisite**

**API Docs / API reference docs**     &#x20;

**Valid authorization scheme and keys:** Depending on your free/paid account with your external system, OR your internal tech implementation of the API, you should have the relevant authorization mechanism and its keys/passwords/tokens handy. Your POC from the external vendor or your tech team shall help you with the same

{% hint style="info" %}
The API URL and the payload can be fetched from the API provider.
{% endhint %}

## **Steps to Configure an External API**

Go to > Campaigns > Channels > External API

<figure><img src="https://1782533751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FazJDZwzHkmWIbkYOetQH%2Fuploads%2F9OGQATpJbPCMAFGxLdRX%2Fimage.png?alt=media&#x26;token=10781c4c-9c8a-43a0-b13b-31c29059445e" alt=""><figcaption></figcaption></figure>

**Step 1:** Click the **+Add New External API** Button

**Step 2:  Add Basic Details**

* **Name:** Name your External API.  This name cannot be editable once it is saved.
* **Description:** Enter the description of your API.
* **Channel:** Choose the channel in which you want the API to communicate with your audience. Lemnisk provides Email and SMS channels for the API to communicate.

{% hint style="info" %}
The performance data of these Emails and SMS will be available in the Reports and Journey builder as usual basis the channel that you select.
{% endhint %}

**Step 3: Add External API Details**

**HTTP Method:** Select the necessary HTTP method from the dropdown. Supported methods: **GET**, **POST**, **PATCH**, **PUT**, and **DELETE**.

**URL:** Add the endpoint URL of your API and enter the variable for path parameters (if any).

URL Path parameters are variable parts of a URL path that are  used to point to a specific resource within a collection

**Adding dynamic path parameters in the URL:**

If you have a path parameter that will change each time you trigger an engagement, you can configure it dynamically by defining the variable in \{{variable\}}. Here's an example to do it:

<figure><img src="https://1782533751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FazJDZwzHkmWIbkYOetQH%2Fuploads%2FuLIef0RxOalvzhFzDBvJ%2Fimage.png?alt=media&#x26;token=39483bac-198f-4824-92eb-bc2f637a3591" alt=""><figcaption><p><em>Image: Dynamic Path Parameters</em></p></figcaption></figure>

{% hint style="info" %}
This URL is custom-made for demonstration purposes
{% endhint %}

\{{Campaign\_ID\}} is the URL path parameter we declared above and added a default value.

The parameters we add to this variable will be reflected while adding the engagement which can be changed later.

<figure><img src="https://1782533751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FazJDZwzHkmWIbkYOetQH%2Fuploads%2FB9dWlOHqfbl3ppyrDPp5%2Fconfig%20parameters%20.png?alt=media&#x26;token=ad0743e2-b9d4-4d7e-b28b-06441a447c0f" alt=""><figcaption><p><em>Image: Default value reflected while creating engagement</em> </p></figcaption></figure>

**Headers:** Add Headers to provide the metadata about the request.

Common headers that are used while making requests:

* Accept
* Content-Type
* Content-length
* Authorization ( use the necessary authorization keys which may vary according to the APIs)
* User-Agent
* Cache-Control
* Connection

**Query Parameter:**

Query parameters are the key-value pairs provided at the end of the URL which gives additional information to the webserver while making the request.

<figure><img src="https://1782533751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FazJDZwzHkmWIbkYOetQH%2Fuploads%2FTPpCoKPKTLW3MgZmmG8g%2Fimage.png?alt=media&#x26;token=792d3e4a-67e9-408b-ab00-94d6fd98ee57" alt=""><figcaption></figcaption></figure>

**Payload:** Paste the payload in the black code edit screen as shown below. You can set the payload to None if the API doesn't have any request body. GET requests will not have any payload however POST APIs may have the payload associated with the API.&#x20;

**Sample Payload:**

```json
{
    "details": {
        "data": {
            "param1": "Sample value", 
            "param2": "Sample value"
        }
    },
    "token": "abc"
}
```

You can set the payload at 2 levels.

**Global Level:** In the Global Level, you define the payload for the API. To define the payload, just enter the JSON payload in the code block. Please ensure that it should be a valid JSON. For invalid JSON, an error will be shown in the UI. If the given payload is correct, it will deploy a tree view. you can add static or dynamic fields, create variables, and add the display term flexibly using the tree formation that enables you to assign values to the parameters based on parent and child objects.

The payload you entered will be displayed in the following tree view.

( This payload is custom-made for demonstration purposes)

<figure><img src="https://1782533751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FazJDZwzHkmWIbkYOetQH%2Fuploads%2Fk7ViwulXbKE0VYcIZcBI%2Fpayloadnew.png?alt=media&#x26;token=cb21f6a4-0bbc-41cd-adf6-742bdd576d40" alt=""><figcaption><p><em>Image: Object Tree</em> </p></figcaption></figure>



```json
{
    "details": {
        "data": {
            "param1": "Sample value", // You can configure these key value parameters by giving name and value which will be displayed in engagement level 
            "param2": "Sample value"
        }
    },
    "token": "abc"
}
```

* To Configure the parameters in engagement level, pass the variable between double curly braces i.e., \{{variable\_name\}}.&#x20;
* Enter the display name which will be shown on the UI as the variable alias, when you're creating engagements for the configured API.
* Enter the default value that assigns value to the parameter by default if the value is not provided by the user, or in the case of Macro when the system fails to replace it with a value.

<figure><img src="https://1782533751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FazJDZwzHkmWIbkYOetQH%2Fuploads%2F1yBqDCpyfPzCspZvsemA%2Fimage.png?alt=media&#x26;token=15329241-5482-4689-bbe5-ef686b030d80" alt=""><figcaption><p><em>Image : Setting the values of the parameter</em></p></figcaption></figure>

## **Optional Field:**&#x20;

* If you wish the field to be mandatory, select No.&#x20;
* Select Yes, if the field needs to be optional. In such a case,  you have to define how to handle the payload when that particular key (param1 in the example) is not provided with a value.

<figure><img src="https://1782533751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FazJDZwzHkmWIbkYOetQH%2Fuploads%2FppEt4ZsknS5mbqkymL0J%2Foptional%20field.png?alt=media&#x26;token=ed2438ab-16cd-4f54-a500-98fb28d1eb32" alt=""><figcaption><p><em>Image: Setting conditions for the empty fields</em></p></figcaption></figure>

**Option 1:** **Send Empty Value (do nothing)**

The parameters will be empty, and the default value will be shown here in all the engagements.

The payload will be:

```json
{
    "details": {
        "data": {
            "param1": " ",
            "param2": "Sample Value 2"
        }
    },
    "token": "abc123"
}
```

**Option 2:** **Drop details.data (Parent Node)**

On Choosing drop details. data, the parent node (Data) will be dropped. The grandparent node (details) and ( Token) will be considered as objects.

The payload will be:

```json
{
    "details": {},
    "token": "abc123"
}
```

**Option 3: Drop details (Grandparent Node)**

On Choosing drop details, the grandparent parent node (Data) will be dropped along with its child ( Data). Only (Token) will be considered as objects.

```json
{
    "token": "abc123"
}
```

**Option 4: Drop the whole Object**

On choosing to drop the whole object, the entire payload will be dropped and the API won't get triggered.

{% embed url="https://drive.google.com/file/d/1bVoearbhXtWLmLDCRThyvqTEgVQtIxrt/view?usp=sharing" %}

**Engagement Level:**

The engagement level payload feature allows users to set a specific payload while creating an engagement instead of defining it at the global level. This flexibility is particularly beneficial when running campaigns with varying payload requirements. By utilizing the engagement level payload, users gain the liberty to send any customized payload when setting up engagements. This feature proves to be highly useful when integrating with external platforms like Mailmodo, where the payload may need to change from one campaign to another. Please note that at this time, our platform exclusively supports **JSON payload** at the engagement level.

{% embed url="https://drive.google.com/file/d/1D4_jeP5EDpRX5pGo0ZLmXU2ZlQGJRjdb/view?usp=sharing" %}
_Demo : Creating Engagement_&#x20;
{% endembed %}
