<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 EditContact function is used to edit an existing contact.

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

Parameters

ContactId - This is the Id of the contact. If you added the contact via the API, you'll already have the Id. If you're using a contact that you entered from the CRM, this page explains how to find the Id. Note: ContactId should be treated like a string, NOT an integer or any other number type.

AssignedTo - (Optional) the UserId of who the contact is assigned to. Here are instructions for finding the correct UserId.

All other fields are the same as the CreateContact function. Note that for the most part, we will only edit the fields you pass us, so you must pass a blank value to clear a field out. The only exception is the ContactName field where if you pass any part of the contact name, we'll update the whole thing (so don't just pass us a middle name, pass the first and last names too) and the custom fields which are all treated as one field, so you must pass in the entire array each time.

Example Code

This code shows how to edit an existing contact.

<?php
/************************************************************************************
    This file demonstrates how to use the Less Annoying CRM API to edit an existing
    contact or company in your 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>";
 
$Function = "CreateContact";
 
/*
Notes:
For more information on formatting these fields, look at the "Create Contact" example
code.
 
This example creates a new contact and then edits it with new information. Editing
companies works in the exact same way. Note that when you edit a contact, only fields
that you pass will be edited, so you need to pass a blank field to clear it out.
*/
 
/*
First we'll create a new contact
*/
$FullName = "Tyler King";
 
$Email = array(
    0=>
array(
        "Text"=>"[email protected]",
        "Type"=>"Work"
    ),
);
 
$Phone = array(
    0=>array(
        "Text"=>"(415) 935-0105", 
        "Type"=>"Work"
    ),
);
 
//Custom fields are all treated as one field, so you must pass in the entire array each time you wish make an update to a custom field
$CustomFields = array(
    "Customer Reference #"=>"123456789",
    "Favorite Color"=>"Green",
);
 
//Now lets put all of those parameters into one array so we can call the API easily
$Parameters = array(
    "FullName"=>$FullName, //You can use the individual name parts instead
    "Email"=>$Email,
    "Phone"=>$Phone,
    "CustomFields"=>$CustomFields
);
 
 
//The CallAPI function is at the bottom of this file
$Result = CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters);
$ContactId = $Result['ContactId'];
 
//Before editing a contact, make sure you have all of their information handy. You need to
//pass the API function all of the fields, even if they're not changing.
//This obviously isn't necessary in this case because we just created the contact, but
//we're calling "GetContact" just as an example
$Function = "GetContact";
$Parameters = array(
    "ContactId"=>$ContactId
);
$Result = CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters);
 
//Now that we have the contact's info, let's change a few things.
//Notice that some of these values are new, and some are taken from the existing record
$Function = "EditContact";
$Parameters = array(
    "ContactId"=>$ContactId,
    "FullName"=>"Angus MacGyver",
    "Phone"=>array(
            0=>array(
                "Text"=>"(555)555-5555", 
                "Type"=>"Work"
            ),
        ),
    "Title"=>"President of microwave and television programming",
    "Birthday"=>"December 3rd",
);
 
//Note: you can assign contacts to other users by also passing an "AssignedTo" parameter
//For example: "AssignedTo"=>111111 (where 111111 is the user's Id)
 
CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters);
 
//That's it, the contact has been edited
 
 
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;
}