thomas-kl1 / php-sdk-zoho-desk

PHP SDK for Zoho Desk API v1 integration.
MIT License
7 stars 10 forks source link

How to fetch threads of a ticket #7

Open ca-dsgn opened 2 years ago

ca-dsgn commented 2 years ago

Hi @thomas-kl1,

I just successfully fetched the data of a ticket via

$ticketDataObject = $gateway->getOperationPool()->getReadOperation('tickets')->get($params["ticket_id"]);

The response I get is this (via print_r):


Zoho\Desk\Model\DataObject Object
--
  | (
  | [entityIdFieldName:protected] => id
  | [data:protected] => Array
  | (
  | [modifiedTime] => 2021-12-09T08:17:06.000Z
  | [subCategory] =>
  | [statusType] => Open
  | [subject] => WG: xxx
  | [dueDate] =>
  | [departmentId] => 182834000000006907
  | [channel] => Email
  | [onholdTime] =>
  | [language] => German
  | [source] => Array
  | (
  | [appName] =>
  | [extId] =>
  | [permalink] =>
  | [type] => SYSTEM
  | [appPhotoURL] =>
  | )
  |  
  | [resolution] =>
  | [sharedDepartments] => Array
  | (
  | )
  |  
  | [closedTime] =>
  | [approvalCount] => 0
  | [isOverDue] =>
  | [isTrashed] =>
  | [createdTime] => 2021-12-07T12:57:57.000Z
  | [id] => 182834000006120001
  | [isResponseOverdue] =>
  | [customerResponseTime] => 2021-12-08T07:42:14.000Z
  | [productId] =>
  | [contactId] => 182834000006131069
  | [threadCount] => 7
  | [secondaryContacts] => Array
  | (
  | )
  |  
  | [priority] =>
  | [classification] =>
  | [commentCount] => 0
  | [taskCount] => 1
  | [accountId] => 
  | [phone] => 
  | [webUrl] => 
  | [isSpam] =>
  | [status] => 
  | [entitySkills] => Array
  | (
  | )
  |  
  | [ticketNumber] => 861
  | [sentiment] =>
  | [customFields] => Array
  | (
  | [Rückmeldung bevorzugt per] =>
  | [Link zu Angebot] =>
  | [Rückmeldung erwünscht bis] =>
  | )
  |  
  | [isArchived] =>
  | [description] =>
  | [timeEntryCount] => 0
  | [channelRelatedInfo] =>
  | [responseDueDate] =>
  | [isDeleted] =>
  | [modifiedBy] => 182834000000069005
  | [followerCount] => 0
  | [email] => xxx
  | [layoutDetails] => Array
  | (
  | [id] => 182834000000083011
  | [layoutName] => Sales
  | )
  |  
  | [channelCode] =>
  | [isFollowing] =>
  | [cf] => Array
  | (
  | [cf_link_zu_angebot] =>
  | [cf_ruckmeldung_bevorzugt] =>
  | [cf_ruckmeldung_erwunscht_bis] =>
  | )
  |  
  | [slaId] =>
  | [layoutId] => 182834000000083011
  | [assigneeId] => 182834000000069005
  | [createdBy] => 182834000000069005
  | [teamId] =>
  | [tagCount] => 0
  | [attachmentCount] => 0
  | [isEscalated] =>
  | [category] =>
  | )
  |  
  | )

I can see in the threadCount, that there are 7 replies on this ticket. My question is, how can I get those threads?

I found this specific information in the zoho desk api documentation, but I am not sure how to implement this using your php interface:

https://desk.zoho.com/DeskAPIDocument#Threads#Threads_Listconversations

Thank you in advance for your help.

Best, Christian

thomas-kl1 commented 2 years ago

Hi @ca-dsgn

Thank you for using this lib! Could you try the following?

`$criteriaBuilder = new ListCriteriaBuilder();

$gateway->getOperationPool()->getListOperation('tickets', [$params["ticket_id"], 'threads'])->get($criteriaBuilder->create())`

It's not documented but you can pass extra arguments to the operation processors

ca-dsgn commented 2 years ago

Hi @thomas-kl1,

thank you for your quick reply and support on this. I really appreciate, that you share this library and that I don't have to implement it by myself completely from scratch ;-)

I inserted your snippet in my code, but I got this fatal error:

Fatal error: Uncaught Error: Call to undefined method Zoho\Desk\Model\Operation\ListOperation::get()

But I looked into the ListOperation class and checked, that the function should be getList() instead of get().

So by using


$criteriaBuilder = new ListCriteriaBuilder();

$gateway->getOperationPool()->getListOperation('tickets', [$params["ticket_id"], 'threads'])->get($criteriaBuilder->create())

I am receiving the threads of the ticket. So working perfect now. Thank you so much!

I have one more question regarding the create action for a ticket:

In your sample code you have this snippet:

$ticketDataObject = $gateway->getDataObjectFactory()->create('tickets', /* Entity values */);

try {
    $ticketDataObject = $gateway->getOperationPool()->getCreateOperation('tickets')->create($ticketDataObject);
} catch (CouldNotSaveException $e) {
    // Handle the exception...
}

Could you give a sample of the section / Entity values /? Is this an object, which has the same structure like the object that the get action gives back? Or is it a associative array?

Thank you very much in advance.

Best, Christian

thomas-kl1 commented 2 years ago

Hi @ca-dsgn glad it helps you and it's working! Indeed the method is getList, not get, my bad..

Regarding the data object factory, the entity values must be an associative array of key-value pair. So it's easy an convenient to create generic data objects :)

If you appreciate the SDK you can add a ⭐, it helps me to who is using it :)

ca-dsgn commented 2 years ago

Hi @thomas-kl1

Ok, great. Thank you for your quick reply on this.

I have one more question:

I just realized, that the resultList objects only contain a summary property, which has a limited number of charaters and then a "..." at the end. So it is just a short summary.

In the documentation of Zoho Desk, I saw, that there should be another field "content" beside "summary", which contains the entire value of the thread. But I couldn't find this field in the response.

https://desk.zoho.com/DeskAPIDocument#Threads

Do you have any idea how to get the entire text of the thread?

thomas-kl1 commented 2 years ago

@ca-dsgn seems it's not possible to get the full content within a list. So I guess you have to fetch the list to get the IDs of the thread so you can fetch them individually.

I need to check if a hack is possible or if I need to implement a new operators for subtypes. When I designed the SDK I didn't used much subtypes such as threads so it doesn't really handle all fine. However I'm thinking of adding a new method to allows it (along the setEntityType). I don't know yet when I can work on it, maybe tonight or Monday

ca-dsgn commented 2 years ago

@thomas-kl1 Wow, thank you so much for your great support!