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:

  1. Office 365;
  2. Microsoft Flow account, sign up via https://emea.flow.microsoft.com/en-us/;
  3. PHP, e.g. install PHP on Ubuntu;
  4. CURL for PHP .

PHP

Create a PHP file which will provide the data to Microsoft Flow, e.g.:


<?php

$body = json_encode([

"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 = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://<your_Microsoft_Flow_HTTP_POST_URL>");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$file = curl_exec($ch);

echo $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:

  1. Receive HTTP request
  2. Call LeadDesk API with module “contact” and command “exists”
  3. Based on the response of the previous API call, make a decision in the flow
  4. If the contact exists, give as response “400” and “Duplicate”
  5. If the contact does not exist, create the contact and give as response “200” and OK

Steps in Flow explained

In this section the steps in the Microsoft Flow are explained.

1.     Specify data to be used by API

Make sure that the request schema matches the fields specified in the PHP file that is used to call the Microsoft Flow. Specify the HTTP POST URL in your PHP file.


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.


3.     Make a decision based on the response

The API call in the previous step gives as response:

  1. {“success”:true,”match”:true}, or
  2. {“success”:true,”match”:false }

In this use case we check if the response of the API call matches
{“success”:true,”match”:true}.

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 (http://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”.