<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 CreateEvent function is used to add an event to your calendar. You can optionally attach contacts and other users to the event if you want.

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

Parameters

Date - The date of the event. The format should be YYYY-MM-DD

StartTime - The start time of the event. The format should be hh:mm (24 hour format). Enter this in the local time based on the timezone set in your CRM account.

EndTime - The end time of the event. The format should be hh:mm (24 hour format). Enter this in the local time based on the timezone set in your CRM account.

Name - The name of the event.

Description - Optional. A text field for entering any other details about the event.

Contacts - Optional. An array with the Ids of the contacts you want to attach to the event. Here are instructions for finding the correct ContactId.

Users - Optional. And array with the Ids of the users that are attending the event. If you leave this parameter out, it will automatically be assigned to you. If you use this parameter, the event will only be assigned to you if you include your own Id in the array. Here are instructions for finding the correct UserId.

Example Code

This code shows you how to create an event using the API.

<?php
/************************************************************************************
    This file demonstrates how to use the Less Annoying CRM API to enter a new event
 
    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>";
 
//First we're going to create two contacts (although you can enter an event without
//attaching it to any contacts if you want
$Function = "CreateContact";
$Parameters = array(
    "FullName" => "Tyler King",
);
 
$Result = CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters);
 
$Contact1 = $Result['ContactId'];
 
//Make contact #2
$Function = "CreateContact";
$Parameters = array(
    "FullName"=>"Bracken King",
);
 
$Result = CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters);
 
$Contact2 = $Result['ContactId'];
 
//Add the ContactIds to an array
$Contacts = array($Contact1, $Contact2);
 
 
//Now we'll enter an event and link it to the contact. Note: Events should be entered 
//using your local time (based on the timezone you set in your CRM account)
$Function = "CreateEvent";
$Parameters = array(
    "Date"=>date('Y-m-d', strtotime('+1 day')), //This date should be formated YYYY-MM-DD,
    "StartTime"=>"14:00", //format should be hh:mm (24 hours format)
    "EndTime"=>"14:30", //format should be hh:mm (24 hours format)
    "Name"=>"Status Meeting", //Required
    "Description"=>"Weekly meeting to discuss our projects", //Optional
    "Contacts"=>$Contacts //Optional
);
 
//Note: you can add users to events by also passing an array of UserIds
//For example: "Users"=>array(1111,2222)
 
$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;
}