I'm using AlexaCRM Toolkit for Dynamics 365 and I'm working on script that bring me results of all invoices for specific contact, the following script show the last ten invoices but for different contacts.
$invoices = $service->retrieveMultipleEntities("invoice", $allPages = false, $pagingCookie = null, $limitCount = 10, $pageNumber = 1, $simpleMode = false);
foreach ($invoices->Entities as $invoice) {
echo 'ID : ' . $invoice->ID . '<br>';
echo 'Name :' . $invoice->name. '<br>';
}
The objective is to get only invoices related to specific contact.
Contact (lookup) is a Foreign key GUID in Invoice entity record. Without filtering the Contact value you are looking for, the query will result you random 10 Invoices from top.
Try to set the WHERE condition in your code.
For example: To filter the Contact by its emailaddress1 attribute, the sample in github look like this:
Another example referring this, you can do something like below to filter the particular Parent Contact.
Note: Am not a php person, to help you I did some research.