LeadDesk API with Microsoft Flow v1.1
Purpose of this example
This example demonstrates how easy you’re able to connect your application with the LeadDesk API. In this use case, we will first check via an API call if the phone number already exists in the customers LeadDesk database, before adding the contact into the customers LeadDesk database in order to prevent duplication of data.
Prerequisites
A person should have access to:
- Office 365;
- Microsoft Flow account, sign up via https://emea.flow.microsoft.com/en-us/;
- PHP, e.g. install PHP on Ubuntu;
- CURL for PHP .
PHP
Create a PHP file which will provide the data to Microsoft Flow, e.g.:
<?php
$body = <strong>json_encode</strong>([
"phone" => "0612345678",
"fname" => "John",
"lname" => "Doe",
"list" => "LeadDesk_Contactlist",
"address" => "Hämeentie 19",
"city" => "Helsinki",
"postcode" => "00500",
"email" => "sales@leaddesk.com",
"gender" => "male",
"other1" => "other 1",
"other2" => "other 2",
"other3" => "other 3",
"other4" => "other 4",
]);
$ch = <strong>curl_init</strong>();
<strong>curl_setopt</strong>($ch, <strong>CURLOPT_URL</strong>, "<u>https://<your_Microsoft_Flow_HTTP_POST_URL></u>");
<strong>curl_setopt</strong>($ch, <strong>CURLOPT_RETURNTRANSFER</strong>, 1);
<strong>curl_setopt</strong>($ch, <strong>CURLOPT_HTTPHEADER</strong>, <strong>array</strong>("Content-Type: application/json"));
<strong>curl_setopt</strong>($ch, <strong>CURLOPT_POST</strong>, 1);
<strong>curl_setopt</strong>($ch, <strong>CURLOPT_POSTFIELDS</strong>, $body);
$file = <strong>curl_exec</strong>($ch);
<strong>echo</strong> $file;
The CURLOPT_URL can be retrieved from Microsoft Flow
Overview Microsoft Flow
This section will provide an overview of the Microsoft Flow. The steps in the Microsoft can be divided into:
- Receive HTTP request
- Call LeadDesk API with module “contact” and command “exists”
- Based on the response of the previous API call, make a decision in the flow
- If the contact exists, give as response “400” and “Duplicate”
- If the contact does not exist, create the contact and give as response “200” and OK
2. Check if contact exists based on the phone number of the contact
Within this step in the Microsoft Flow, the LeadDesk API is called with module “contact” and command “exists”. With the attribute “phone”, the supplied phone number is used to check if the phone number already exists in the database.
If the phone number exists in the database, the LeadDesk API will give as a response “{“success”:true,”match”:true}”.
If the phone number does not exists in the database, the LeadDesk API will give as a response “{“success”:true,”match”:false”.
4. Phone number exists
If the phone number exists, the response gives as response “400” and “Duplicate”.
In this use case. the Microsoft Flow stops after this step, but it’s possible to extend the flow with extra functionality. For example, when it’s determined that the phone number exists in the database, an e-mail could be sent informing that the contact has not been created in order to prevent duplicate data by extending the Microsoft Flow with the Outlook connector.
5. Phone number does not exists
If the response message equals {“success”:true,”match”:false}, the contact does not exists in the customer LeadDesk database and the Microsoft Flow goes into the “If no” decision point, and calls the LeadDesk API with the module “contact” and command “add” to create the contact. In the add contact API call we use the attributes we specified in the first step. In the LeadDesk API site (https://leaddesk.com/docs/original-api-modules/ ) you can see which other attributes you can send.
After the contact has been created, the LeadDesk API sends as response “200” and “OK”.