Skip to content

Commit 4252c75

Browse files
committed
sample codes
1 parent c273238 commit 4252c75

File tree

6 files changed

+101
-53
lines changed

6 files changed

+101
-53
lines changed

.DS_Store

0 Bytes
Binary file not shown.

JAVASCRIPT , jQuery/.DS_Store

0 Bytes
Binary file not shown.

JAVASCRIPT , jQuery/js/zohodesk-sdk.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ class zohodeskAPI {
440440
console.log("URL:" + url);
441441
console.log("htt:" + http_settings.headers);
442442
var result=null;
443+
url='https://mobilesupport.localzoho.com/api/v1/tickets/3220000001196208/threads?authtoken=7e5631cec7b6144db56a834f663aa4cd&orgId=11141888';
443444
$.ajax({
444445
method: http_settings.method,
445446
url: url,

PHP/.DS_Store

0 Bytes
Binary file not shown.

PHP/ZohoDesk_API.php

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
const ZOHOBASE_URL="https://desk.zoho.com/api/v1/";
4+
35
function logio($txt){
46
echo $txt."<br><br>";
57
}
@@ -32,7 +34,7 @@ function delete($id, $obj) {
3234
$url = $this->buildURL($this->getPrimaryURL($id));
3335
return $obj->httpDELETE($url);
3436
}
35-
function info($id, $params, $obj) {
37+
function get($id, $params, $obj) {
3638
$param = ($params) ? $this->handleParameters($params) : "";
3739
$url = $this->buildURL($this->getPrimaryURL($id), $param);
3840
return $obj->httpGET($url);
@@ -151,7 +153,7 @@ function delete($parent_id, $id, $obj) {
151153
$url = $this->buildURL($this->getPrimaryURL($parent_id, $id));
152154
return $obj->httpDELETE($url);
153155
}
154-
function info($parent_id, $id, $params, $obj) {
156+
function get($parent_id, $id, $params, $obj) {
155157
$param = ($params) ? $this->handleParameters($params) : "";
156158
$url = $this->buildURL($this->getPrimaryURL($parent_id, $id), $param);
157159
return $obj->httpGET($url);
@@ -343,12 +345,15 @@ function createTicket($data) {
343345
function updateTicket($id, $data) {
344346
return $this->tickets->update($id, $data,$this);
345347
}
346-
function ticketDetails($id, $params = "") {
347-
return $this->tickets->info($id, $params,$this);
348+
function getTicket($id, $params = "") {
349+
return $this->tickets->get($id, $params,$this);
348350
}
349-
function allTickets($params = "") {
351+
function getTickets($params = "") {
350352
return $this->tickets->all($params,$this);
351353
}
354+
function deleteTicket($params = "") {
355+
return $this->tickets->delete($params,$this);
356+
}
352357

353358
function allComments($ticketID, $params = "") {
354359
return $this->comments->all($ticketID, $params,$this);
@@ -365,11 +370,11 @@ function updateComment($ticketID, $commentID, $comment_data) {
365370
function deleteComment($ticketID, $commentID) {
366371
return $this->comments->delete($ticketID, $commentID,$this);
367372
}
368-
function commentDetails($ticketID, $commentID, $params = "") {
369-
return $this->comments->info($ticketID, $commentID, $params,$this);
373+
function getComment($ticketID, $commentID, $params = "") {
374+
return $this->comments->get($ticketID, $commentID, $params,$this);
370375
}
371376

372-
function allContacts($params = "") {
377+
function getContacts($params = "") {
373378
return $this->contacts->all($params,$this);
374379
}
375380
function createContact($data) {
@@ -384,11 +389,11 @@ function updateContact($id, $data) {
384389
function deleteContact($id) {
385390
return $this->contacts->delete($id,$this);
386391
}
387-
function contactDetails($id, $params = "") {
388-
return $this->contacts->info($id, $params,$this);
392+
function getContact($id, $params = "") {
393+
return $this->contacts->get($id, $params,$this);
389394
}
390395

391-
function allAccounts($params = "") {
396+
function getAccounts($params = "") {
392397
return $this->accounts->all($params,$this);
393398
}
394399
function createAccount($data) {
@@ -403,11 +408,11 @@ function updateAccount($id, $data) {
403408
function deleteAccount($id) {
404409
return $this->accounts->delete($id,$this);
405410
}
406-
function accountDetails($id, $params = "") {
407-
return $this->accounts->info($id, $params,$this);
411+
function getAccount($id, $params = "") {
412+
return $this->accounts->get($id, $params,$this);
408413
}
409414

410-
function allTasks($params = "") {
415+
function getTasks($params = "") {
411416
return $this->tasks.all($params,$this);
412417
}
413418
function createTask($data) {
@@ -422,40 +427,40 @@ function updateTask($id, $data) {
422427
function deleteTask($id) {
423428
return $this->tasks->delete($id,$this);
424429
}
425-
function taskDetails($id, $params = "") {
426-
return $this->tasks->info($id, $params,$this);
430+
function getTask($id, $params = "") {
431+
return $this->tasks->get($id, $params,$this);
427432
}
428-
function ticketTasks($ticketId,$params=""){
433+
function getTicketTasks($ticketId,$params=""){
429434
return $this->tasks->tasksOfTicket($ticketId, $params,$this);
430435
}
431436

432-
function allAgents($params = "") {
437+
function getAgents($params = "") {
433438
return $this->agents->all($params,$this);
434439
}
435-
function agentDetails($id, $params = "") {
436-
return $this->agents->info($id, $params,$this);
440+
function getAgent($id, $params = "") {
441+
return $this->agents->get($id, $params,$this);
437442
}
438443

439444
function allDepartments($params = "") {
440445
return $this->departments->all($params,$this);
441446
}
442-
function departmentDetails($id, $params = "") {
443-
return $this->departments->info($id, $params,$this);
447+
function getDepartment($id, $params = "") {
448+
return $this->departments->get($id, $params,$this);
444449
}
445450
function buildURL($url, $params = null) {
446451
return ($params !== null) ? $url . $params : $url;
447452
}
448453
function httpGET($url) {
449-
$this->httpExecute($url,$this->httpHeaders(),"GET");
454+
return $this->httpExecute($url,$this->httpHeaders(),"GET");
450455
}
451456
function httpPOST($url, $data) {
452-
$this->httpExecute($url,$this->httpHeaders(),"POST",$data);
457+
return $this->httpExecute($url,$this->httpHeaders(),"POST",$data);
453458
}
454459
function httpPATCH($url, $data) {
455-
$this->httpExecute($url,$this->httpHeaders(),"PATCH",$data);
460+
return $this->httpExecute($url,$this->httpHeaders(),"PATCH",$data);
456461
}
457462
function httpDELETE($url) {
458-
$this->httpExecute($url,$this->httpHeaders(),"DELETE");
463+
return $this->httpExecute($url,$this->httpHeaders(),"DELETE");
459464
}
460465
function httpHeaders() {
461466
$authtoken = $this->authtoken;
@@ -469,13 +474,14 @@ function httpExecute($url,$headers,$method,$data=""){
469474
$curl= curl_init($url);
470475
curl_setopt($curl,CURLOPT_HTTPHEADER,$headers);
471476
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,$method);
477+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
472478

473479
if($method=="POST" || $method=="PATCH"){
474480
curl_setopt($curl, CURLOPT_POSTFIELDS, (gettype($data)==="string")?$data:json_encode($data));
475481
}
476482
$response= curl_exec($curl);
477483
curl_close($curl);
478-
return ($response);
484+
return json_decode($response);
479485
}
480486
function httpSettings($method, $headers, $data = "") {
481487
// $settingsObj = {

PHP/example.php

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,70 @@
1-
<html>
2-
3-
<body>
4-
<div style="width:800px;">
5-
<pre>
61
<?php
72

8-
require_once 'ZohoDesk_API.php';
9-
10-
$me=new stdClass();
11-
$me->accountName="Vijay's PHP ac";
12-
$me->phone="2727982";
13-
$me->email="vijayphp@php.net";
14-
15-
$options=new stdClass();
16-
$options->limit=1;
17-
18-
$som=new zohodeskAPI('59550a0e2b1a864a31bef962363e029f',652853630);
19-
$som->allTickets();
20-
21-
22-
3+
require_once 'ZohoDesk_API.php';
4+
5+
$ZOHODESK_API = new zohodeskAPI('YOUR_AUTH_TOKEN', YOUR_ORG_ID); //Replace your values
6+
7+
/**** Tickets ******/
8+
9+
//Get tickets
10+
$ticketsJSON = $ZOHODESK_API->getTickets();
11+
12+
//Create a ticket
13+
$ticketFields = array(
14+
"subject" => "My ticket subject",
15+
"contactId" => 329372998233, //YOUR CONTACT ID
16+
"departmentId" => 328739287873 //YOUR DEPARTMENT ID
17+
);
18+
//$createdTicket = $ZOHODESK_API->createTicket($ticketFields);
19+
20+
//Get a ticket
21+
//$ticket_id = 372662979823;
22+
//$ticketJSON = $ZOHODESK_API->getTicket($ticket_id);
23+
24+
//Update a ticket
25+
//$ticket_id = 372662979823;
26+
//$createdTicket = $ZOHODESK_API->updateTicket($ticket_id, $ticketFields);
27+
28+
//Delete a ticket
29+
//$ZOHODESK_API->deleteTicket($ticket_id);
30+
31+
/**** End of Tickets ******/
32+
33+
34+
35+
36+
37+
38+
/**** Contacts ******/
39+
40+
//Get contacts
41+
//$contactsJSON = $ZOHODESK_API->getContacts();
42+
43+
//Create a contact
44+
//$contactFields = array(
45+
"lastName" => "Vijaaaay"
46+
);
47+
//$createdContact = $ZOHODESK_API->createContact($contactFields);
48+
49+
//echo json_encode($createdContact);
50+
51+
//Get a contact
52+
//$contact_id = 372662979823;
53+
//$contactJSON = $ZOHODESK_API->getContact($contact_id);
54+
55+
//Update a contact
56+
//$contact_id = 32838297938;
57+
//$updatedContact = $ZOHODESK_API->updateContact($contact_id, $contactFields);
58+
59+
//Delete a contact
60+
//$contact_id = 32838297938;
61+
//$ZOHODESK_API->deleteContact($contact_id);
62+
63+
/**** End of Contacts ******/
64+
65+
66+
67+
/***** Same for COMMENTS, ACCOUNTS, TASKS, AGENTS, DEPARTMENTS ****/
68+
2369

24-
//echo substr($myn, 0, strlen($myn)-1);
25-
?>
26-
</pre>
27-
</div>
28-
</body>
29-
</html>
70+
?>

0 commit comments

Comments
 (0)