infusionsoft / infusionsoft-php

PHP client library for the Infusionsoft API.
https://developer.infusionsoft.com/
Other
129 stars 126 forks source link

$infusionsoft->contacts()->find($contactid, $fields); returns all contacts #253

Open xemacscode opened 4 years ago

xemacscode commented 4 years ago

$contact = $infusionsoft->contacts()->find($contactid, $fields); I'm trying to use this to get a full contact details with a certain id. But it is returning all contacts even if I provided the id for a specific contact. How to solve this issue?

ajohnson6494 commented 4 years ago

I think you have a syntax error. It should be something like:

$fields = "custom_fields,lead_source_id`;
$contactid = 123456;
$contact = $infusionsoft->contacts()->with($fields)->find($contactid);
xemacscode commented 4 years ago

so fields are not array? @ajohnson6494

xemacscode commented 4 years ago
$fields = 'Id', 'Email','AccountId','Username','LastName','FirstName','MiddleName','City', 'Company', 'Country', 'Phone1','PostalCode','State', 'custom_fields';
                // $fields = array();
                $contact = $infusionsoft->contacts()->with($fields)->find($contactid);

I tried this but it is not working.

xemacscode commented 4 years ago

It still returns multiple if not all contacts.

ajohnson6494 commented 4 years ago

Correct, fields is a string value and not an array. So you would want to do something like:

$fields = 'Id,Email,AccountId,Username,LastName,FirstName,MiddleName,City,Company,Country,Phone1,PostalCode,State,custom_fields';
xemacscode commented 4 years ago

I tried that, but the result still contains multiple contacts. I think the find($contactid); is being ignored.

xemacscode commented 4 years ago

The SDK in my opinion is poorly documented. Not all methods in REST documentation is applicable to the SDK and we have to jump back and forth between calling REST methods and XML-RPC methods. I don't know if it is intentional but the documentation isn't clear.

ajohnson6494 commented 4 years ago

What are you passing into the find function call? because it is only returning one contact for me.

xemacscode commented 4 years ago

The contact id that I got from webhook.

Will this return custom fields? I have added custom field to the Contact. Will this return the custom field I created or do I have to specify on the optional_parameters?

Ultimater commented 3 years ago

If you're just trying to pull up a single contact, you can use the load method instead:

$contact = $infusionsoft->contacts()->load($contactid, $fields);

The rest API doesn't appear to have a field to specify the contactId when you're trying to pull multiple contacts at once unfortunately: https://keys.developer.keap.com/docs/keap-150k/1/routes/contacts/get

Might try it with the email instead to get the hang of the REST api.

If you need to pull more than one contact at once by contactId, you can use the deprecated XMLRPC and its Table Schema like so:

$contactIds = [123,321];
$contacts = $infusionsoft->data()->query('Contact',1000,0,['Id'=>$contactIds],$fields,'Id',true);