helpscout-api-php icon indicating copy to clipboard operation
helpscout-api-php copied to clipboard

How to get Conversation ID?

Open yaphawhann opened this issue 3 years ago • 3 comments

This is not an issue, but I need help.

After calling:

$conversations = $client->conversations()->list($filters); echo json_encode($conversations);

All I get was:

{"0":{}}

How do I get the conversation ID?

yaphawhann avatar Mar 16 '22 11:03 yaphawhann

👋 It looks like the $filters aren't matching any conversations which is the result set is empty. You can adjust your filters to provide some Conversations provided there are some within the mailbox you're working with. Once you're seeing conversations there, you can follow this example for how to access the results.

bkuhl avatar Mar 16 '22 17:03 bkuhl

I removed all possible filters, as below:

<?php
require __DIR__ . '/vendor/autoload.php';
require '_credentials.php';

use HelpScout\Api\ApiClientFactory;
use HelpScout\Api\Conversations\Conversation;
use HelpScout\Api\Conversations\ConversationFilters;
use HelpScout\Api\Conversations\ConversationRequest;
use HelpScout\Api\Conversations\CustomField;
use HelpScout\Api\Conversations\Threads\ChatThread;
use HelpScout\Api\Conversations\Threads\PhoneThread;
use HelpScout\Api\Tags\Tag;
use HelpScout\Api\Customers\Customer;
use HelpScout\Api\Entity\Collection;

    //Creating Client Object
$client = ApiClientFactory::createClient();
$client = $client->useClientCredentials(APP_ID, APP_SECRET);

// List conversations
$conversations = $client->conversations()
    ->list()
    ->getFirstPage()
    ->toArray();

$filters = (new ConversationFilters())
    ->inMailbox(8089)
    ->inStatus('all')
    ->sortField('createdAt')
    ->sortOrder('asc');

$conversations = $client->conversations()->list($filters);
echo json_encode($conversations);
?>

And it returned this:

{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"20":{},"21":{},"22":{},"23":{},"24":{}}

Can't figure what I did wrong... will appreciate some/any help.

yaphawhann avatar Mar 16 '22 18:03 yaphawhann

I think it's querying the results successfully, which is why it's showing there's 24 empty objects in that last comment. All of the properties on Conversation are private which is why I think it's coming through as an empty object in the output. I suspect if you iterated over them and echoed the data, you'd be able to access the data you're looking for.

foreach ($conversations as $conversation) {
    echo $conversation->getId().PHP_EOL;
}

bkuhl avatar Mar 16 '22 19:03 bkuhl

Closing this issue due to inactivity. Please feel free to reopen if needed!

miguelrs avatar Dec 18 '23 19:12 miguelrs