API anrop för att skapa en konversation från PHP

Här är ett kort exempel på hur du anropar LiveAgent API och skapar en konversation med anpassade fält.

 

<?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' => 'efafeb2d6522964ba137870b9a5124e7'

);

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);

}

?>