my problem is how to add CUSTOM_FIELD
or other double nested JSON like ADDRESS
using PHP classes provided at Github/insightly:
$contact = (object)array('ADDRESSES' =>(object) array('ADDRESS_TYPE' => 'POSTAL','COUNTRY' => $data[4]));
$contact = $this->addContact($contact);
$data = json_encode($contact);
print_r($data);
I am trying to create the object from below JSON:
{
"FIRST_NAME": "Andy",
"LAST_NAME": "Nguyen",
"BACKGROUND": "McD is a fast food company with lot of franchies around the world",
"VISIBLE_TO": "EVERYONE",
"CUSTOMFIELDS": [
{
"CUSTOM_FIELD_ID": "CONTACT_FIELD_1",
"FIELD_VALUE": "Industry"
},
{
"CUSTOM_FIELD_ID": "CONTACT_FIELD_2",
"FIELD_VALUE": "Range of Investment"
},
{
"CUSTOM_FIELD_ID": "CONTACT_FIELD_3",
"FIELD_VALUE": "https://www.McD.com"
},
{
"CUSTOM_FIELD_ID": "CONTACT_FIELD_4",
"FIELD_VALUE": "https://www.dropbox.com/s/u5vykgsxhfi7x6c/McD%202017%20ASEAN%20Food%20In%20Asia.pdf?dl=3"
}
],
"ADDRESSES": [
{
"ADDRESS_TYPE": "POSTAL",
"COUNTRY": "Malaysia"
}
],
"CONTACTINFOS": [
{
"TYPE": "EMAIL",
"LABEL": "WORK",
"DETAIL": "Andy@Mcd.com"
}
],
"LINKS": [
{
"OPPORTUNITY_ID": null,
"ORGANISATION_ID": 106787363,
"ROLE": "CEO",
}
],
}
However the data source is in Excel Format. So I use PHPExcel to convert it into JSON format and send it to another function that performs JSON ENCODE.
I am using Stdclass()
like below:
$contact = new stdClass();
$contact->CUSTOMFIELDS -> CUSTOM_FIELD_ID = "CONTACT_FIELD_1";
$contact->CUSTOMFIELDS -> CUSTOM_FIELD_ID = $data;
but it doesn't work because they read it as a string not as an object, can anyone help me?