This example will add a contact to a contact list ready to be called. This example can be modified to be used for example to gather leads from your website.

$auth = '1234567889'; // LeadDesk client auth key.

// Mandatory fields
$phones = '0401234567,+358501234567'; //Phonenumbers for the contact. Numbers are separated by comma. Phone number needs to be at least 3 characters long. Only 4 valid numbers will be added to contact. If more than 4 numbers were given, they will be ignored.
$list = 5486; // Contact list ID (integer) or name (string). Created contact is added to this list (by id or name). Or new list is created if list with given name is not found. Or exception if this parameter is integer and list cannot be found.

// Optional fields
$fname = 'John'; //	Contact's first name
$lname = 'Doe'; // Contact's last name
$email = ''; // Contact's email address
$www = ''; // Contact's home page
$address = 'Oakstreet 5'; // Contact's street address
$postcode = '65789'; // Contact's postal code
$city = 'London'; // Contact's city
$country = 'England'; // Contact's country
$ssc = '121276-3451'; // Contact's social security code
$birthyear = '1976'; // Contact's year of birth
$gender = 'male'; // Contact's gender
$companyid = '1234'; // Contact's company id
$company = 'Company Plc'; // Contact's company name (ignored if company ID is set)
$vatin = '123456780'; // Contact's company VAT identification number (ignored if company ID is set)
$title = 'Salesworker'; // Contact's title
$comment = 'Notes and additional info'; // Contact's comment
$other1 = 'some other info'; // Contact's other info. Up to 35.
$other2 = 'more info'; // Contact's other info. Up to 35.
$other_label1 = 'Info One'; // Contact's other info label (associated with other info). Up to 35.
$other_label2 = 'Info Two'; // Contact's other info label (associated with other info). Up to 35.

$order = 'first';
/* Contact's running number in the contact list. Values can be: "first" / "last" / 0-100% / {number}. Default value is "last". Explanations:
first: Contact will be set first in the calling list
last: Contact will be set last in the calling list
0-100%: Contact will be set by percent from the start. 0% means first, 50% means middle and 100% means last
{number}: Contact will be set by order number (integer) in the calling list */

$assign_to_agent = 'agentone'; // Assigns contact to an agent. Agent id or username.

$url = "{$auth}&mod=contact&cmd=add&fname={$fname}&lname={$lname}&phone={$phones}&list={$list}&return_value=1"; // The return_value will return a value back as JSON that will look something like this: {"contact_id":4647024,"success":true}

// Using curl to send a request
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);


if ($httpcode == 200) {
    echo "Contact has been added successfully! Body: {$result}";
} else {
    echo "Failed to added contact. HTTP Code: {$httpcode}, Body: {$result}";