Home > Technical Support > LiveAgent API > REST API > Examples > API call to create conversation from PHP

API call to create conversation from PHP

Here is a short example how to call LiveAgent API and create a conversation with custom fields.
 

<?php

$service_url = 'http://localhost/LiveAgent/LiveAgent/server/api/index.php?handler=conversations';

$curl = curl_init($service_url);

//use custom field codes defined by administrator, otherwise they will not be visible in ticket detail (but still inserted to DB)

$arrcustomVars = array(array('code'=>'varsymbol', 'value'=>'43894209'), array('code'=>'anotherfield', 'value'=>'test value'));

 

$curl_post_data = array(

        'message' => 'test message',

        'useridentifier' => 'example@example.com',

        'department' => '38ff3d45', //department id

        'subject' => 'My first conversation',

        'recipient' => 'example@example.com',

        'customfields' => json_encode($arrcustomVars),

        'apikey' => '<<YOUR API KEY>>'

);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);

$curl_response = curl_exec($curl);

 

if ($curl_response === false) {

    $info = curl_getinfo($curl);

    curl_close($curl);

    die('error occured during curl exec. Additioanl info: ' . var_export($info));

}

curl_close($curl);

$decoded = json_decode($curl_response);

if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {

    die('error occured: ' . $decoded->response->errormessage);

}

?>

Ready to try LiveAgent?

It's free for the first 14 days! No credit card required.

Get Started
We work well with others...
Magento Joomla Wordpress Mailchimp
Contact us

support@ladesk.com

+1-800-811-6590 (Toll Free in USA & Canada)

+421 2 33 456 826 (European Union & Worldwide)

Quality Unit, LLC 616 Corporate Way, Suite 2-3278 Valley Cottage, NY 10989

Stay in touch
Blog Google+
© 2004-2015 QualityUnit.com, All rights reserved