<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 CreateTask function is used to add a task in your CRM. You can optionally attach tasks to contacts and assign them to other users.

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

Parameters

DueDate - The date the task is due. If you enter it in the past, it will show up as an overdue task. The format should be YYYY-MM-DD

Name - The name of the task. This is generally something like "Follow up with John Doe."

Description - Optional. Any additional information related to this task.

ContactId - Optional. The Id of a the contact this task is related to. Here are instructions for finding the correct ContactIdNote: ContactId should be treated like a string, NOT an integer or any other number type.

AssignedTo - Optional. If you want to assign this task to another user, pass their UserId using this parameter. Here are instructions for finding the correct UserId.

Example Code

This code shows you how to add a task using the API.

<?php
/************************************************************************************
    This file demonstrates how to use the Less Annoying CRM API to enter a new task
 
    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 a contact (although you can enter a task without
//attaching it to a contact if you want
$Function = "CreateContact";
$Parameters = array(
    "FullName"=>"Tyler King",
);
 
$Result = CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters);
 
//Get the new ContactId
$ContactId = $Result['ContactId'];
 
//Now we'll enter a task about the contact
$Function = "CreateTask";
$Parameters = array(
    "DueDate"=>date('Y-m-d', strtotime('+1 day')), //This date should be formated YYYY-MM-DD
    "Name"=>"Follow up with Tyler", //Required, the name of the task
    "Description"=>"He is interested, should call back ASAP" //Optional
    "ContactId"=>$ContactId //Optional
);
 
//Note: you can assign tasks to other users by also passing an "AssignedTo" parameter
//For example: "AssignedTo"=>111111 (where 111111 is the user's Id)
 
$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;
}