I have tried the this code: $record = $record['data']->Company; but it is always returned as null. I have also tried $record = $record[1]->data->Company; which also results in a null value. I have read so many answers and tried the solutions but nothing works for me.
Some more experience than me please have a look and let me know where i am going wrong.
Thanks in advance
{
"1": {
"index": 1,
"data": {
"CONTACTID": "3345923000000546002",
"SMOWNERID": "3345923000000158021",
"Contact Owner": "Frank Rosa",
"First Name": "Administrator",
"Last Name": "Ian",
"Email": "[email protected]",
"Created Time": "2018-09-19 14:32:35",
"Modified Time": "2018-09-20 02:48:51",
"Full Name": "Administrator Ian",
"Description": "Equity and Empowerment through Education. It is the Mission of 3e LLC to promote equity and empowerment for all students through engaging professional development for educators and parents, one-on-one coaching for teacher efficacy, and mentoring services for youth to promote enrichment and success. For the empowered, we offer editing, transcribing, and ghostwriting services to ensure your voice is heard.",
"Last Activity Time": "2018-09-20 02:48:51",
"Instagram Url": "http://www.instagram.com/3e_llc",
"Company": "3ELLC",
"Website": "https://www.3ellc.org",
"Phone_1": "(727) 420-1050",
"Full Address": "2152 Arcadia Rd, Holiday, FL 34690, USA",
"Facebook Url": "http://www.facebook.com/3eLLC/",
"Logo Url": "https://dev.energypages.com/wp-content/uploads/2018/05/header-logo-57.png",
"Twitter Url": "http://www.twitter.com/3e_llc",
"Membership Level": "Basic",
"Select Service": "Technology",
"User ID": "347"
}
}
}
I am getting the json from my function below:
function webhook_listener($request_data){
$client = new ZohoCRMClient('Contacts', 'API KEY HERE');
$parameters = $request_data->get_params();
if( !isset( $parameters['contactId'] ) || empty($parameters['contactId']) ){
file_put_contents(plugin_dir_path( __FILE__ ).'invalid.txt', 'No parameter found');
return array( 'error' => 'no_parameter_given' );
}else{
$companyid = $parameters['contactId'];
file_put_contents(plugin_dir_path( __FILE__ ).'crm.txt', $parameters);
$record = $client->getRecordById()->id($companyid)->request();
wp_mail( '[email protected]', 'Post Data', $record );
$payload = json_decode($record, true);
$payload = $payload[1]['data']['Company'];
file_put_contents(plugin_dir_path( __FILE__ ).'record.txt', $payload);
return $payload;
}
}
$record = json_decode($str, true);