Skip to content

Commit 300d8e9

Browse files
author
vijay
committed
tasks for a ticket added
1 parent 8fa6064 commit 300d8e9

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed

JAVASCRIPT , jQuery/js/zohodesk-sdk.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,16 +457,17 @@ class zohodeskAPI {
457457
});
458458
}
459459
getValidJson(string) {
460-
console.log(string);
460+
// console.log(string);
461461
switch (typeof string){
462462
case "object":
463463
return string;
464464
break;
465465
case "string":
466466
try{
467467
var obj=JSON.parse(string);
468-
return obj;
469-
}catch (exception) {
468+
return (typeof obj==="object")?obj:false;
469+
}
470+
catch (exception) {
470471
return false;
471472
}
472473
return false;

PHP/ZohoDesk_API.php

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ function getPrimaryURL($id = null) {
5757
function handleParameters($data) {
5858
$params = "";
5959
if (gettype($data) === "object"){
60-
foreach ($data as $item) {
61-
$params .= $item . "=" . $data[$item] . "&";
60+
foreach ($data as $key=>$value) {
61+
$params .= $key . "=" . $value . "&";
6262
}
6363
} else {
6464
return "?" . $data;
6565
}
66-
return "?" . $params.substr(0, $params.length - 1);
66+
return "?" . $params.substr(0, strlen($params) - 1);
6767
}
6868
function passedRequires($data) {
6969
try {
@@ -72,7 +72,7 @@ function passedRequires($data) {
7272
if(gettype($data)=="array" || gettype($data)=="object"){
7373
foreach ($this->requiredFields as $item=>$value) {
7474
if (($dataType=="array") ? array_key_exists($item, $dataObj): property_exists($dataObj, $item)) {
75-
if (($dataType=="array")?!$dataObj[$item]:!$dataObj->$item) {
75+
if ($value) {
7676
logio("ERROR : Field " . $item . " is required to create new " . $this->name . "");
7777
$this->printRequired();
7878
return false;
@@ -89,7 +89,6 @@ function passedRequires($data) {
8989
logio("ERROR : Data is not valid JSON".$e);
9090
return false;
9191
}
92-
logio("All required fields present");
9392
return true;
9493
}
9594
function required() {
@@ -166,17 +165,23 @@ function buildURL($url, $params = null) {
166165
return ($params !== null) ? $url . $params : $url;
167166
}
168167
function getPrimaryURL($parent_id = null, $id = null) {
169-
$returnURL = zohodeskAPI_vars.appBaseURL;
168+
$returnURL = ZOHOBASE_URL;
170169
$type = $this->name;
171-
if ($parent_id !== null) {
170+
if ($parent_id !== null && trim($parent_id)!=="") {
172171
$returnURL .= $this->parent_name . "/" . $parent_id;
173172
if ($id !== null) {
174173
$returnURL .= "/" . $this->name . "/" . $id;
175174
} else {
176175
$returnURL .= ($type === $this->name) ? "/" . $this->name : "";
177176
}
178177
} else {
179-
$returnURL .= $this->parent_name;
178+
try{
179+
throw new Exception("ERROR : ".$this->parent_name."-ID is empty or missing ");
180+
}
181+
catch (Exception $e){
182+
echo $e->getMessage();
183+
}
184+
return FALSE;
180185
}
181186
return $returnURL;
182187
}
@@ -194,24 +199,23 @@ function handleParameters($data) {
194199
function passedRequires($data) {
195200
try {
196201
$dataObj = (gettype($data) === "object") ? $data :json_decode($data);
197-
foreach ($this->requiredFields as $item) {
198-
if ($dataObj->hasOwnProperty($item)) {
199-
if (!$dataObj[$item]) {
200-
logio("ERROR : Fieldl " . $item . " is required to create new " . $this->name . "");
202+
foreach ($this->requiredFields as $item=>$value) {
203+
if (property_exists($dataObj, $item)) {
204+
if (!$data->$item) {
205+
logio("ERROR : Field " . $item . " is empty & required to create new " . $this->name . "");
201206
$this->printRequired();
202207
return false;
203208
}
204209
} else {
205-
logio("ERROR : Fieldl " . $item . " is required to create new " . $this->name . "");
210+
logio("ERROR : Field " . $item . " is required to create new " . $this->name . "");
206211
$this->printRequired();
207212
return false;
208213
}
209214
}
210215
} catch (Exception $e) {
211-
logio("ERROR : Data is not valid JSON");
216+
logio("ERROR : Data is not valid JSON".$e->getMessage());
212217
return false;
213218
}
214-
logio("All required fields present");
215219
return true;
216220
}
217221
function required() {
@@ -220,7 +224,7 @@ function required() {
220224
function printRequired() {
221225
logio("Required fields to create new " . $this->name . " are ");
222226
$i = 0;
223-
foreach ($this->requiredFields as $item) {
227+
foreach ($this->requiredFields as $item=>$value) {
224228
logio((++$i) . " : " . $item);
225229
}
226230
logio("-------------");
@@ -278,51 +282,58 @@ function __construct($auth_token, $orgId) {
278282
$this->departments = new zohodeskAPI_ReadOnly_Obj("departments");
279283

280284
$this->tickets->quickCreate = function ($subject, $departmentId, $contactId, $productId = "", $email = "", $phone = "", $description = "") {
281-
return array(
285+
return json_encode(array(
282286
"subject"=> $subject,
283287
"departmentId"=> $departmentId,
284288
"contactId"=> $contactId,
285289
"productId"=> $productId,
286290
"email"=> $email,
287291
"phone"=> $phone,
288292
"description"=> $description
289-
);
293+
));
290294
};
291295
$this->comments->quickCreate = function ($ticketID,$content, $isPublic = true) {
292-
return array(
296+
return json_encode(array(
293297
"content"=> $content,
294298
"isPublic"=> ($isPublic)?"true":"false"
295-
);
299+
));
296300
};
297301

298302
$this->contacts->quickCreate = function ($lastName, $firstName = "", $email = "", $phone = "", $description = "") {
299-
return array(
303+
return json_encode(array(
300304
"lastName"=> $lastName,
301305
"firstName"=> $firstName,
302306
"email"=> $email,
303307
"phone"=> $phone,
304308
"description"=> $description
305-
);
309+
));
306310
};
307311
$this->accounts->quickCreate = function ($accountName, $email = "", $website = "") {
308-
return array(
312+
return json_encode(array(
309313
"accountName"=> $accountName,
310314
"email"=> $email,
311315
"website"=> $website
312-
);
316+
));
313317
};
314318
$this->tasks->quickCreate = function ($departmentId, $subject, $description = "", $priority = "", $ticketId = null) {
315-
return array(
319+
return json_encode(array(
316320
"departmentId"=> $departmentId,
317321
"subject"=> $subject,
318322
"description"=> $description,
319323
"priority"=> $priority,
320324
"ticketId"=> $ticketId
321-
);
325+
));
326+
};
327+
$this->tasks->tasksOfTicket = function ($ticketId,$params,$obj) {
328+
$param = ($params) ? $this->tasks->handleParameters($params) : "";
329+
$url = $this->tasks->buildURL(ZOHOBASE_URL."tickets/$ticketId/tasks", $param);
330+
return $obj->httpGET($url);
322331
};
323332

324333
}
325-
334+
static function getBaseUrl(){
335+
return ZOHOBASE_URL;
336+
}
326337
function createTicket($data) {
327338
$arguments = func_get_args();
328339
$dataJsonObj= $this->getValidJson($data);
@@ -403,16 +414,19 @@ function createTask($data) {
403414
$arguments = func_get_args();
404415
$dataJsonObj= $this->getValidJson($data);
405416
$dataObj = ($dataJsonObj)?$dataJsonObj: call_user_func_array($this->tasks->quickCreate,$arguments);
406-
return $this->tasks.create($dataObj,$this);
417+
return $this->tasks->create($dataObj,$this);
407418
}
408419
function updateTask($id, $data) {
409-
return $this->tasks.update($id, $data,$this);
420+
return $this->tasks->update($id, $data,$this);
410421
}
411422
function deleteTask($id) {
412-
return $this->tasks.delete($id,$this);
423+
return $this->tasks->delete($id,$this);
413424
}
414425
function taskDetails($id, $params = "") {
415-
return $this->tasks.info($id, $params,$this);
426+
return $this->tasks->info($id, $params,$this);
427+
}
428+
function ticketTasks($ticketId,$params=""){
429+
return $this->tasks->tasksOfTicket($ticketId, $params,$this);
416430
}
417431

418432
function allAgents($params = "") {

PHP/testfile.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
$me->phone="2727982";
1313
$me->email="vijayphp@php.net";
1414

15+
$options=new stdClass();
16+
$options->limit=1;
17+
1518
$som=new zohodeskAPI('59550a0e2b1a864a31bef962363e029f',652853630);
16-
$som->createAccount($me);
19+
$som->ticketTasks('215666000000154051',$options);
20+
21+
22+
1723

18-
$myn="1234567";
1924
//echo substr($myn, 0, strlen($myn)-1);
2025
?>
2126
</pre>

0 commit comments

Comments
 (0)