helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API
MIT License
98 stars 62 forks source link

Getting email ids for customers #315

Closed jackjwatts closed 9 months ago

jackjwatts commented 9 months ago

Thank you for taking the time to submit an issue with all the details shown below. Our engineering team monitors issues submitted and strives to respond with 1-2 business days.

Current behavior calling

$conversation = $client->conversations()->get($conversationId);
$conversation->getCustomer()->getEmails() 

does not return the ids of the emails. To get around this I'm having to do

$conversation = $client->conversations()->get($conversationId);
$customerid = $conversation->getCustomer();
$customer = $client->customers()->get($customerId);
$emails = $customer->getEmails();

Expected behavior calling $conversation->getCustomer()->getEmails() would return the ids of the emails.

Steps to reproduce

  1. create a conversation, with a customer with an email (however the customer is created is irrelevant I think)
  2. call $conversation->getCustomer()->getEmails() and notice that email id is empty ..
miguelrs commented 9 months ago

Hey @jackjwatts 👋

Actually that's by design. If you look at the API docs for GET Conversation you'll see that the API only returns the customer email as a string (e.g. "xyz@test.com"), so we can only populate the Email::$value property.

If you want all the data about the customer emails, then you'll need to make another request to the GET Customer endpoint. You can do it explicitly like in your workaround, although probably a better option is passing a ConversationRequest object, like:

$conversationRequest = new ConversationRequest();
$conversationRequest->withPrimaryCustomer();
$conversation = $client->conversations()->get($conversationId, $conversationRequest);

This will automatically make another request to GET Customer for you behind the scenes.

Hope this helps!