<aside> ⚠️ Note: This documentation is for the first version of our API which is now deprecated. You should probably be looking at the docs for our new API instead, which you can find here.

</aside>

The DeleteContact function is used to remove contacts from your CRM.

When calling this function, the Function parameter sent to the API should be DeleteContact.

Parameters

ContactId - The Id of a the contact you want to delete. Here are instructions for finding the correct ContactId.

Note: ContactId should be treated like a string, NOT an integer or any other number type.

Example Code

This code shows how to delete an existing contact.

<?php
/************************************************************************************
    This file demonstrates how to use the Less Annoying CRM API to delete a contact 
    or company from the CRM
 
    If you have any questions, feel free to email [email protected] for help
**************************************************************************************/
 
//Get your user UserCode and API token from <https://www.lessannoyingcrm.com/app/Settings/Api>
$UserCode = "ABCDE";
$APIToken = "111111111111111111111111111111111111111111111111";
$EndpointURL = "<https://api.lessannoyingcrm.com>";
 
/*
Notes:
This function requires a ContactId parameter. Even if you're deleting a company,
pass the id in as "ContactId." As you can read about in our help documentation,
contacts and companies are the same thing in our database, so they both fit under
the "Contact" label in API functions.
*/
 
//First let's create an example contact
$Function = "CreateContact";
$Parameters = array(
    "FullName"=>"Tyler King",
);
 
$Result = CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters);
 
//Get the new ContactId
$ContactId = $Result['ContactId'];
 
$Function = "DeleteContact";
//All we need to do is set the ContactId
$Parameters = array(
    "ContactId"=>$ContactId
);
 
//This will delete the contact we just added
$Result = CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters);
 
function CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters){
    $PostData = array(
      'UserCode' => $UserCode,
      'APIToken' => $APIToken,
      'Function' => $Function,
      'Parameters' => json_encode($Parameters),
    );
    $Options = array(
        'http' =>
            array(
                'method'  => 'POST', //We are using the POST HTTP method.
                'header'  => 'Content-type: application/x-www-form-urlencoded',
                'content' => http_build_query($PostData) // URL-encoded query string.
            )
    );
    $StreamContext  = stream_context_create($Options);
    $APIResult = file_get_contents("$EndpointURL?UserCode=$UserCode", false, $StreamContext);
    $APIResult = json_decode($APIResult, true);
    if(@$APIResult['Success'] === true){
        echo "Success!";
    }
    else{
        echo "API call failed. Error:".@$APIResult['Error'];
        exit;
    }
    return $APIResult;
}