Skip to content

Retrieve entity's related items

Zhmayev Yaroslav edited this page Nov 30, 2017 · 1 revision

Sometimes you need to retrieve a list of entities related to an entity. For example a list of tickets created for a contact:

$johnSmithId = $client->entities->getID('Contacts', [
    'firstname'             => 'John',
    'lastname'              => 'Smith',
]);

// List ALL the tickets created for John Smith
$entities=$client->invokeOperation('retrieve_related', [
        'id'    => $johnSmithId,
        'relatedType'  => 'HelpDesk',
        'relatedLabel'  => 'HelpDesk'
], 'GET');

// ..alternatively you could use SQL-like queries with WHERE, ORDER BY, LIMIT etc
$entities=$client->invokeOperation('query_related', [
        'query' => "SELECT * FROM HelpDesk WHERE ticket_title LIKE '%problem%' ORDERBY modifiedtime LIMIT 10",
        'id'    => $johnSmithId,
        'relatedLabel'  => 'HelpDesk'
], 'GET');

// The output
array(1) {
  [0]=>
  array(23) {
    ["ticket_no"]=>
    string(3) "TT1"
    ["ticketpriorities"]=>
    string(3) "Low"
    ["ticketstatus"]=>
    string(11) "In Progress"
    ["ticket_title"]=>
    string(17) "Problem with APIs"
    ["contact_id"]=>
    string(4) "12x8"
    ...
   }
}

Clone this wiki locally