Using New ZOHO CURL REST APIs in Creator
Hello,
this Post will show the way i use to PUSH, GET, UPDATE and so on, Data from the Creator Deluge Script to for example the
New Zoho DESK API via PHP-Script.
My Deluge code example to add a Ticket in Zoho Desk:
urltwo = "
http://YourURL.com/phpfile.php?value=
60¶m=" +
TicketID + "&string=";
StringRec =
"
{
\"secondsSpent\" : \"0\",
\"executedTime\" : \"" + thisapp.GetDataFromDesk.TimeStringForTimeEntry() + "\",
\"customFields\" :
{
\"TaskID\" : \"" + TaskID + "\"
},
\"minutesSpent\" : \"" + minutes + "\",
\"agentCostPerHour\" : \"0\",
\"description\" : \"" + subjectRec + "\",
\"hoursSpent\" : \"" + hours + "\",
\"requestChargeType\" : \"Customer Service\"
}";
TicketResponse = getUrl(urltwo + StringRec);
My PHP-Script example:
<?php
//string = JsonRec -> Json data
//value = value to get the right call
//param = Needed ID
//PHP variables
//$what = Standard POST
//$url = Call URL
//$data = Needed Data
//$headers = Authentication
if($_GET["string"] && $_GET["value"]){
$JsonRec =
$_GET["string"];
$value =
$_GET["value"];
$BooksOrgID = '1234567
8'; // Add Your Books ORG-ID here
$BooksAPIKey = 'aa11a1a1aaa1a1aa1a1a111a1a1'; // Add Your Books API-Key here
$DeskOrgID = '09876543'; // Add Your DESK ORG-ID here
$DeskAPIKey = 'a11a1a1a11a1aaa1a1a1aa1a1a'; // Add Your DESK API-Key here
$what = 'POST';
$headers = '';
//BOOKS
if($value == 10){
//https://www.zoho.com/books/api/v3/#Contacts_Create_a_Contact
$url = '
https://books.zoho.com/api/v3/contacts';
$data = array(
"organization_id" => $BooksOrgID,
'authtoken' => $BooksAPIKey,
'JSONString' => $JsonRec
);
} else if($value == 20){
//https://www.zoho.com/books/api/v3/#Items_Create_an_Item
$url = '
https://books.zoho.com/api/v3/items';
$data = array(
"organization_id" => $BooksOrgID,
'authtoken' => $BooksAPIKey,
'JSONString' => $JsonRec
);
} else if($value == 22){
//https://www.zoho.com/books/api/v3/#Items_Get_an_item
$param = $_GET["param"];
$url = '
https://books.zoho.com/api/v3/items/'.$param;
$headers = array('Authorization: Zoho-authtoken '.$BooksAPIKey, 'Content-Type: application/json;charset=UTF-8');
$what = 'GET';
} else if($value == 21){
//https://www.zoho.com/books/api/v3/#Items_Update_an_item
$param = $_GET["param"];
$url = '
https://books.zoho.com/api/v3/items/'.$param;
$data = array(
'JSONString' => $JsonRec
);
$what = 'PUT';
$headers = array('Authorization: Zoho-authtoken '.$BooksAPIKey, 'Content-Type: application/json;charset=UTF-8');
} else if($value == 30){
//https://www.zoho.com/books/api/v3/#Invoices_Create_an_invoice
$url = '
https://books.zoho.com/api/v3/invoices';
$data = array(
"organization_id" => $BooksOrgID,
'authtoken' => $BooksAPIKey,
'JSONString' => $JsonRec
);
} else if($value == 32){
//https://www.zoho.com/books/api/v3/#Invoices_Get_an_invoice
$param = $_GET["param"];
$url = '
https://books.zoho.com/api/v3/invoices/'.$param;
$headers = array('Authorization: Zoho-authtoken '.$BooksAPIKey, 'Content-Type: application/json;charset=UTF-8');
$what = 'GET';
} else if($value == 31){
//https://www.zoho.com/books/api/v3/#Recurring-Invoices_Create_a_Recurring_Invoice
$url = '
https://books.zoho.com/api/v3/recurringinvoices';
$data = array(
"organization_id" => $BooksOrgID,
'authtoken' => $BooksAPIKey,
'JSONString' => $JsonRec
);
} else if($value == 32){
//https://www.zoho.com/books/api/v3/#Recurring-Invoices_Update_Recurring_Invoice
$param = $_GET["param"];
$url = '
https://books.zoho.com/api/v3/recurringinvoices/'.$param;
$data = array(
"organization_id" => $BooksOrgID,
'authtoken' => $BooksAPIKey,
'JSONString' => $JsonRec
);
//DESK
}else if($value == 40){
//https://desk.zoho.com/DeskAPIDocument#TicketTimeEntry#TicketTimeEntry_ListTicketTimeEntries
$param = $_GET["param"];
$url = '
https://desk.zoho.com/api/v1/tickets/'.$param.'/timeEntry';
$headers = array('orgId:'.$DeskOrgID, 'Authorization:Zoho-authtoken '.$DeskAPIKey);
$what = 'GET';
} else if($value == 41){
//https://desk.zoho.com/DeskAPIDocument#TicketTimeEntry#TicketTimeEntry_GetaTicketTimeEntry
$param = $_GET["param"];
$paramtwo = $_GET["paramtwo"];
$url = '
https://desk.zoho.com/api/v1/tickets/'.$param.'/timeEntry/'.$paramtwo;
$headers = array('orgId:'.$DeskOrgID, 'Authorization:Zoho-authtoken '.$DeskAPIKey);
$what = 'GET';
} else if($value == 50){
//https://desk.zoho.com/DeskAPIDocument#Search
$param = $_GET["param"];
$url = '
https://support.zoho.com/api/v1/search?searchStr='.$param.'&module=tickets&from=0&limit=200';
$headers = array('orgId:'.$DeskOrgID, 'Authorization:Zoho-authtoken '.$DeskAPIKey);
$what = 'GET';
} else if(
$value == 60){
//https://desk.zoho.com/DeskAPIDocument#TicketTimeEntry#TicketTimeEntry_ListTicketTimeEntries
$param =
$_GET["param"];
$url = '
https://support.zoho.com/api/v1/tickets/'.
$param.'/timeEntry';
$headers = array('orgId:'.$DeskOrgID, 'Authorization:Zoho-authtoken '.$DeskAPIKey, 'Content-Type:application/json');
$data =
$JsonRec;
} else if($value == 70){
//https://desk.zoho.com/DeskAPIDocument#Tasks#Tasks_Listtasksbyticket
$param = $_GET["param"];
$url = '
https://desk.zoho.com/api/v1/tickets/'.$param.'/tasks?limit=50';
$headers = array('orgId:'.$DeskOrgID, 'Authorization:Zoho-authtoken '.$DeskAPIKey);
$what = 'GET';
} else if($value == 80){
//https://desk.zoho.com/DeskAPIDocument#Tasks#Tasks_Getatask
$param = $_GET["param"];
$url = '
https://desk.zoho.com/api/v1/tasks/'.$param.'?include=tickets';
$headers = array('orgId:'.$DeskOrgID, 'Authorization:Zoho-authtoken '.$DeskAPIKey);
$what = 'GET';
} else if($value == 90){
//https://desk.zoho.com/DeskAPIDocument#Tasks#Tasks_Getatask
$param = $_GET["param"];
$url = '
https://desk.zoho.com/api/v1/tickets/'.$param;
$headers = array('orgId:'.$DeskOrgID, 'Authorization:Zoho-authtoken '.$DeskAPIKey);
$what = 'GET';
} else if($value == 91){
//https://desk.zoho.com/DeskAPIDocument#Tasks#Tasks_Updateatask
$param = $_GET["param"];
$url = '
https://desk.zoho.com/api/v1/tasks/'.$param;
$data = '{"status" : "In Progress"}';
$headers = array('orgId:'.$DeskOrgID, 'Authorization:Zoho-authtoken '.$DeskAPIKey);
$what = 'PATCH';
} else if($value == 92){
//https://desk.zoho.com/DeskAPIDocument#Tasks#Tasks_Updateatask
$param = $_GET["param"];
$url = '
https://desk.zoho.com/api/v1/tasks/'.$param;
$data = '{"ownerId" : '.$JsonRec.',"status" : "In Progress"}';
$headers = array('orgId:'.$DeskOrgID, 'Authorization:Zoho-authtoken '.$DeskAPIKey);
$what = 'PATCH';
}
$curl = curl_init(
$url);
if($what == 'GET'){
curl_setopt_array($curl, array(
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true
));
} else if($what == 'POST') {
curl_setopt_array(
$curl, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS =>
$data,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true
));
} else if($what == 'PUT'){
curl_setopt_array($curl, array(
CURLOPT_POST => 1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
));
} else if($what == 'PATCH'){
curl_setopt_array($curl, array(
CURLOPT_POST => 1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
));
}
$result = curl_exec($curl);
var_dump($result);
} else {
echo "No String returned!";
}
?>
Example Response:
string(597) "{"customFields":{"Tema":null,"TaskID":"1111111111111"},"ownerId":"44444444444444","requestChargeType":"Customer Service","executedTime":"2017-10-17T16:06:57.000Z","hoursSpent":"0","minutesSpent":"45","secondsSpent":"0","agentCostPerHour":"0.0","additionalCost":null,"totalCost":"0.0","description":"Example description","createdTime":"2017-10-17T15:06:59.058Z","createdBy":"555555555555","id":"6666666666666"}"
The Yellow Marks are Links to the API Dokumentation Web-Page
The Turquoise Marks are OrgID and Auth-Token you must add
I Hope this will help someone to make API Calls out of Creator Deluge with the New CURL APIs from Zoho.
All there included Values are testet and working fine in my Applications.
If anyone have a better way to solve this issue, tell me please.
If anyone add some Values in the PHP Script, tell me too, please.