Figuring out how to do address arrays on a Netsuite Customer can be rather complicated so I thought I would share some sample code:
$CustomerAddressBooks = array();
foreach ($addresses as $address) {
//populate the approprate varables i.i. $street, $City, etc from $address
$addrArray = array(
"defaultBilling" => $DefaultBilling,
"defaultShipping" => $DefaultShipping,
"addr1" => $Street,
"addr2" => $Street2,
"label" => $Street,
"city" => $City,
"phone" => $Phone,
"country" => $NsCountryCode,
"addressee" => $Addressee,
"attention" => $attention,
"zip" => $Zip
);
$CustomerAddressBook = new nsComplexObject('CustomerAddressbook');
$CustomerAddressBook->setFields($addrArray);
$CustomerAddressBooks[] = $CustomerAddressBook;
}
$CustomerAddressBookList = new nsComplexObject('CustomerAddressbookList');
$CustomerAddressBookList->setFields(array(
"addressbook" => $CustomerAddressBooks
));
$customerInformationArray = array(
"email" => $email,
"phone" => $phone,
"addressbookList" => $CustomerAddressBookList,
"creditCardsList" => $CCCList
);

Hi Daniel, thanks for the sample code as always!
I am having some trouble figuring out how to retrieve and display the address from netsuite. I can retrieve and display nearly all other fields (i.e. internalId, firstname, lastname, company, phone, fax and email but cannot for the life of me get the address.
Any tip would be greatly appreciated, please send me your email address so I can send a little thank you via paypal.
Michael
I sent an email to the msowen account you mentioned in another comment. Let me know if you didn’t receive it. You can contact me at danielmahaffy@gmail.com or daniel@ozonesolutions.com.
Can you post your emailed solution here? I’d also like to know how to easily display address of customers in Netsuite via php. Thanks
Sure. Here you go: Netsuite Address API Example
Daniel,
Thank you, as always your code snippets are a great help!
Worked like a charm… thanks for posting
hi
how can we set value for custom fields for customer? any idea
thanks
Maysam, take a look at this post: Setting custom fields in Netsuite. It isn’t for a customer, but the code is basically the same.
thank you very much
now i need to be able to search based on custom fields, any idea?
You can also just send an array (even with multiple addresses) and Netsuite does the rest. But – as in your solution as well – you won’t get the addresses internalID which is bad if you need to map Netsuite records with your own systems records.
$addrArray = array(
…
‘addressbook’ => array(
array(
“addr1″ => $bill,
“addr2″ => $billingAddress->getAddress4(),
“city” => $billingAddress->getCity(),
“zip” => $billingAddress->getPostcode(),
‘defaultBilling’ => ‘true’
),
array(
“addr1″ => $ship,
“addr2″ => $shippingAddress->getAddress4(),
“city” => $shippingAddress->getCity(),
“zip” => $shippingAddress->getPostcode(),
‘defaultShipping’ => ‘true’
)
)
);