"Creating default object from empty value" error for Customer phone and email in Quickbooks api

122 Views Asked by At

I had been using the intuit's Quickbooks Api to connect with the admin panel. Currently using only to create a Customer record from the Admin panel. I'm able to add Name, Company Name but not able to add Phone and Email details. Following is the code:

function qb_insert($name,$company,$phone,$email){   
    $requestValidator = new OAuthRequestValidator(QB_accessToken,QB_accessTokenSecret,QB_consumerKey,QB_consumerSecret);
    $serviceType= IntuitServicesType::QBO;
    $serviceContext = new ServiceContext(QB_realmId, $serviceType, $requestValidator);
    $dataService = new DataService($serviceContext);

    $customerObj = new IPPCustomer(); 
    $customerObj->Name = $name; 
    $customerObj->CompanyName = $company; 
    $customerObj->GivenName = $name;
    $customerObj->DisplayName = $name;
    $customerObj->PrimaryEmailAddr->Address = $email;
    $customerObj->PrimaryPhone->FreeFormNumber = $phone;
    $resultingCustomerObj = $dataService->Add($customerObj);
    return $resultingCustomerObj;
}

If you take a closer look,I had been using PrimaryPhone, Phone,AlternatePhone, Mobile, PrimaryEmailAddr but none of them works. A Customer is being created with only Name and Company name.

Thanks in advance.

Regards, Arun

1

There are 1 best solutions below

0
On BEST ANSWER

So I had to answer my own question :P

I didn't find this easily. I took a closer look over the output given by (SELECT * FROM Customer) using Query of the Api and got the following:

...blah...blah "PrimaryPhone" :{ "FreeFormNumber" : 74114xxxxx } ...blah...blah

This is the reason why I started to use $customerObj->PrimaryPhone->FreeFormNumber.

I searched through the API code for FreeFormNumber and found IPPTelephoneNumber class under which this is created.

Similarly IPPEmailAddress class for Email.

Finally, got it worked doing the following:

For Phone

$customerObj->PrimaryPhone = new IPPTelephoneNumber(); $customerObj->PrimaryPhone->FreeFormNumber = $phone;

And For Email

$customerObj->PrimaryEmailAddr = new IPPEmailAddress(); $customerObj->PrimaryEmailAddr->Address = $email;

PS: A sincere request to any big products who provide APIs please provide a relevant example instead of loads and loads of DOCS!