I'm trying to create a variable and place it in an array. Like this:
$ch = curl_init('https://apps.net-results.com/api/v2/rpc/server.php?Controller=Contact');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,
json_encode(
array(
'id' => uniqid(),
'method' => 'getMultiple',
'jsonrpc' => '2.0',
'params' => array(
'offset' => 0,
'limit' => 50, // 10, 25, or 50
'order_by' => 'contact_email_address', //'contact_email_address' or 'contact_id'
'order_dir' => 'ASC', //'ASC' or 'DESC'
)
)
)
);
$strResponse = curl_exec($ch);
$strCurlError = curl_error($ch);
if (!empty($strCurlError)) {
//handle curl error
echo "Curl Error<br />$strCurlError<br />";
} else {
//check for bad user/pass
if ($strResponse == "HTTP/1.0 401 Unauthorized: Your username name and/or password are invalid.") {
//handle login error
echo "Error<br />$strResponse<br />";
} else {
//successful call, check for api success or error
$objResponse = json_decode($strResponse);
if (property_exists($objResponse, 'error') && !is_null($objResponse->error)) {
//handle error
$intErrorCode = $objResponse->error->code;
$strMessage = $objResponse->error->message;
$strData = $objResponse->error->data;
echo "Error<br />Code: $intErrorCode<br />Message: $strMessage<br />Data: $strData<br />";
} else {
//handle success
//echo "Success<br />";
$objResult = $objResponse->result;
$intTotalRecords = $objResult->totalRecords;
//echo "Total Records: $intTotalRecords<br />";
$arrContacts = $objResult->results;
//echo $arrContacts[0]->country;
//echo $arrContacts[3]->last_name;
//echo "<pre>";
//print_r($arrContacts);
//echo "<pre/>";
}
}
}
I'm not sure this is possible. I have tried doing different things such as creating a class, and placing the function in the class in the array, but it doesn't work. Can anyone give me the correct syntax of what I should try?