Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new service to handle multi entity levels #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

thomas-kl1
Copy link
Owner

No description provided.

@thomas-kl1 thomas-kl1 self-assigned this Dec 11, 2021
@thomas-kl1 thomas-kl1 linked an issue Dec 11, 2021 that may be closed by this pull request
@thomas-kl1 thomas-kl1 assigned thomas-kl1 and unassigned thomas-kl1 Dec 13, 2021
@thomas-kl1
Copy link
Owner Author

Hi @ca-dsgn

Could you take a look? This is minimal effort to cover almost all endpoints of the Zoho desk API. However for subtypes entities it requires to set the path and bind the value to interpolate. I will document it but basically it means that you can tell the path: "tickets/{ticket_id}/threads/{thread_id}" and bind an array: ['ticket_id'=> 23, 'thread_id' => 8]

@thomas-kl1
Copy link
Owner Author

Hi @stefnats I'd love to get your feedback too!

@thomas-kl1 thomas-kl1 linked an issue Dec 13, 2021 that may be closed by this pull request
@ca-dsgn
Copy link

ca-dsgn commented Dec 14, 2021

Hi @thomas-kl1,

I just pulled your branch develop-service and tried to understand how to update my code. I saw, that you gitignored your /docs/sample/code/test.php file. Could you update the sample code for your enhancement, so that I can a better understanding of what to do for fetching a thread of a ticket?

Thank you in advance.

Best,
Chris

@thomas-kl1
Copy link
Owner Author

thomas-kl1 commented Dec 16, 2021

@ca-dsgn in your case you can use it as following:

$criteriaBuilder = new ListCriteriaBuilder();
$criteriaBuilder->setFields(['id','subject', 'email', 'description','webUrl']);
$ticketList = $gateway->getServiceFactory()->listOperation('tickets')->getList($criteriaBuilder->create());
$threadList = $gateway->getServiceFactory()->listOperation('threads', 'tickets/{ticket_id}/threads')->getList($criteriaBuilder->create(), ['ticket_id' => $ticketId]);

@thomas-kl1
Copy link
Owner Author

@ca-dsgn I've added some sample so you can use them for you tests. Let me know if everything works fine

@ca-dsgn
Copy link

ca-dsgn commented Dec 16, 2021

@thomas-kl1 I tried this code snippet to get the list of full threads (of a ticket):

$criteriaBuilder = new ListCriteriaBuilder();

$ticketThreads = $gateway->getServiceFactory()->listOperation('threads', 'tickets/'.$params["ticket_id"].'/threads')->getList($criteriaBuilder->create(), [

  'ticket_id' => $params["ticket_id"]
]);

I am getting this error:
Mandatory field "entityType" is not set.

I tried to pass a field entityType (entity_type) next to ticket_id, but it seems that this needs to be passed at a different place. Do you have any ideas?

Best,
Christian

@thomas-kl1
Copy link
Owner Author

@ca-dsgn my bad! Sorry I have a little access to dev currently and did a little update from my phone. Could you pull and tray again?

@ca-dsgn
Copy link

ca-dsgn commented Dec 16, 2021

@thomas-kl1 I am getting the list of threads now (but like before just with the short summary). Do I have to make a seperate call for each thread to get the full details of a thread? If so, could you give an example for this as well?

@ca-dsgn
Copy link

ca-dsgn commented Dec 16, 2021

@thomas-kl1

I updated my code now to iterate over all threads and request the detailed thread for each:

$serviceFactory = $gateway->getServiceFactory();

foreach($ticketThreads as $thread) {

  $data = $thread->toArray();
  
  $thread_id = $data["id"];
  
  $threadDetail =  $serviceFactory->readOperation('threads', 'tickets/'.$params["ticket_id"].'/threads/'.$thread_id.'',[
  
	  "ticket_id" => $params["ticket_id"],
	  "thread_id" => $data["id"]
  
  ]);
  
  print_r($threadDetail);
}

But the object I am getting now (print_r) has no detailed values in it. Do I have to pass anything else to receive more fields in the result?

@thomas-kl1
Copy link
Owner Author

Hi @ca-dsgn , sorry for the late reply.

In order to pull the threads list you have to use this call:

$threadList = $serviceFactory->listOperation('threads', 'tickets/{ticket_id}/threads')->getList($criteriaBuilder->create(), ['ticket_id' => $ticketId]);

Regarding "/tickets/{ticket_id}/sendReply" it should be used like the threads, so:

$replyDataObject = $serviceFactory->createOperation('sendReply', 'tickets/{ticket_id}/sendReply')->create($replyDataObject, ['ticket_id' => $ticketDataObject->getEntityId()]);

@thomas-kl1
Copy link
Owner Author

@ca-dsgn in order to read a thread:

$threadDataObject = $serviceFactory->readOperation('threads', 'tickets/{ticket_id}/threads/{thread_id}')->get(['ticket_id' => $ticketId, 'thread_id' => $threadId]);

@thomas-kl1 thomas-kl1 marked this pull request as ready for review January 15, 2022 19:43
@thomas-kl1 thomas-kl1 added the enhancement New feature or request label Jan 15, 2022
@ca-dsgn
Copy link

ca-dsgn commented Jan 18, 2022

Hi @thomas-kl1,

no worries - I am very happy that you answered my question. I tried to create a ticket reply, but I am not sure what the $replyDataObject is as well as the $ticketDataObject. Could you give an extended example with those variables set?

@ca-dsgn
Copy link

ca-dsgn commented Jan 18, 2022

@ca-dsgn in order to read a thread:

$threadDataObject = $serviceFactory->readOperation('threads', 'tickets/{ticket_id}/threads/{thread_id}')->get(['ticket_id' => $ticketId, 'thread_id' => $threadId]);

@thomas-kl1 I already did that (as mentioned in my comment from Dec 16 last year) but the response object does not have any detailed values in it. I tried to use the toArray() method on the responseObject - but that didn't work. Could you give a example on how to fetch the full thread text from the responseObject?

@ca-dsgn
Copy link

ca-dsgn commented Mar 4, 2022

@ca-dsgn in order to read a thread:
$threadDataObject = $serviceFactory->readOperation('threads', 'tickets/{ticket_id}/threads/{thread_id}')->get(['ticket_id' => $ticketId, 'thread_id' => $threadId]);

@thomas-kl1 I already did that (as mentioned in my comment from Dec 16 last year) but the response object does not have any detailed values in it. I tried to use the toArray() method on the responseObject - but that didn't work. Could you give a example on how to fetch the full thread text from the responseObject?

@thomas-kl1 Just wanted to kindly reask you for my questions on top. Thank you very much in advance.

@thomas-kl1
Copy link
Owner Author

@thomas-kl1 I am getting the list of threads now (but like before just with the short summary). Do I have to make a seperate call for each thread to get the full details of a thread? If so, could you give an example for this as well?

Hi, thank you for your patience, I don't have much time to work on this side-project.
So yes it seems you have to fetch the entities one by one in order to get the full text (that's sad).
In order to get the detailed thread you must do what you said on Dec 16, 2021. Do you still get no data in response? Would you be comfortable trying to debug the sdk and fix it?

@thomas-kl1
Copy link
Owner Author

Reading https://desk.zoho.com/DeskAPIDocument#Threads#Threads_Getathread and https://desk.zoho.com/DeskAPIDocument#Include seems you can include specific fields from the API to be fetched along the response.

@thomas-kl1
Copy link
Owner Author

thomas-kl1 commented Mar 15, 2022

@thomas-kl1

I updated my code now to iterate over all threads and request the detailed thread for each:

$serviceFactory = $gateway->getServiceFactory();

foreach($ticketThreads as $thread) {

  $data = $thread->toArray();
  
  $thread_id = $data["id"];
  
  $threadDetail =  $serviceFactory->readOperation('threads', 'tickets/'.$params["ticket_id"].'/threads/'.$thread_id.'',[
  
	  "ticket_id" => $params["ticket_id"],
	  "thread_id" => $data["id"]
  
  ]);
  
  print_r($threadDetail);
}

But the object I am getting now (print_r) has no detailed values in it. Do I have to pass anything else to receive more fields in the result?

I just figured out that you actually create the readService but never call the get method that will fetch the entity from the API. Try with the following:

$serviceFactory = $gateway->getServiceFactory();
$readOperation = $serviceFactory->readOperation('threads', 'tickets/{ticket_id}/threads/{thread_id}');
 
foreach($ticketThreads as $thread) {
    $threadDetail = $readOperation->get(['ticket_id' => $params['ticket_id'], 'thread_id' => $thread->getEntityId()]);
   
    print_r($threadDetail);
}

And if you want to use the include parameter e.g: the plainText field:

$serviceFactory = $gateway->getServiceFactory();
$readOperation = $serviceFactory->readOperation('threads', 'tickets/{ticket_id}/threads/{thread_id}');
 
foreach($ticketThreads as $thread) {
    $threadDetail = $readOperation->get(['ticket_id' => $params['ticket_id'], 'thread_id' => $thread->getEntityId()], ['include' => 'plainText']);
   
    print_r($threadDetail);
}

@thomas-kl1 thomas-kl1 added the help wanted Extra attention is needed label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to upload Ticket Attachments How to fetch threads of a ticket
2 participants