intuit / QuickBooks-V3-PHP-SDK

Official PHP SDK for QuickBooks REST API v3.0: https://developer.intuit.com/
Apache License 2.0
241 stars 240 forks source link

Customer object does not return CustomField values. #497

Open BarnumD opened 1 year ago

BarnumD commented 1 year ago

I've gone into the QBO GUI to a customer, created a custom field, populated the field, then tried to call the customer via the API

function getQuickbooksCustomer($dataService, $customerId){
  $dataService->throwExceptionOnError(true);

  $customer = $dataService->FindbyId('customer', $customerId);

  return $customer;
}

$qbCustomer = getQuickbooksCustomer($dataService, '1000');
print("<pre>".print_r($qbCustomer,true)."</pre>");

The resulting customer object has a blank customfields section: [CustomField] =>

russellgilbert commented 12 months ago

Same problem here. I also see that running a query in the API Explorer doesn't return custom fields either.

cliffordvickrey commented 11 months ago

Here's how I was able to achieve this (took me a very long time to figure it out :-( ):

<?php
/** @var \QuickBooksOnline\API\DataService\DataService $dataService */
$preferences = $dataService->getCompanyPreferences();
/** @var \QuickBooksOnline\API\Data\IPPSalesFormsPrefs $salesFormPreferences */
$salesFormPreferences = $preferences->SalesFormsPrefs;
/** @var list<\QuickBooksOnline\API\Data\IPPCustomFieldDefinition> $defs */
$defs = $salesFormPreferences->CustomField;

// custom field names indexed by ID
$customFieldsParsed = [];

if (count($defs) > 1) {
    /** @var list<\QuickBooksOnline\API\Data\IPPCustomField> $customFields */
    $customFields = $defs[1]->CustomField;

    foreach ($customFields as $customField) {
        $customFieldId = \substr($customField->Name, -1);
        $customFieldsParsed[$customFieldId] = $customField->StringValue;
    }
}

\var_dump($customFieldsParsed);
?>
russellgilbert commented 11 months ago

cliffordvickrey said: Here's how I was able to achieve this...

Thanks very much for looking into this!

However, this isn't really what I'm looking for (or what the OP is looking for either, I think). When I run your code, I get a list of three custom field names:

customFieldsParsed:
array(3) {
  [3]=> string(18) "Collection Ranking"
  [2]=> string(9) "Sales Rep"
  [1]=> string(11) "P.O. Number"
}

But I'm looking for the actual values for these custom fields when querying customers, not just the custom field names. So for example, I want to know what the "Collection Ranking" is for each customer.

And curiously, I actually have several more custom fields that aren't included in the array above. When I edit a customer and scroll down to the "Custom fields" section, I see only one of the three fields listed above ("Collection Ranking"), plus five more that aren't listed.

image

I think that's because when I go to the gear icon, then "Custom fields", I see that "Collection Ranking" has a category of "Customer", while "Sales Rep" and "P.O. Number" have a category of "Transaction". But I don't understand why the other five "Customer" category fields aren't in the array above with "Collection Ranking", even though they have the exact same permissions as "Collection Ranking".

image