try
{
// create a new cURL resource
$ch = curl_init();
$EngineMailerApiPath = "https://api.enginemailer.com/restapi/subscriber/emsubscriber/updateSubscriber";
// Add APIKey into the Headers to be passed in.
$apiKey = "API Key Here";
$headers =["APIKey:".$apiKey];
// Custom Fields declarations
$jsonCustomFields1->customfield_key = "customfield_key";
$jsonCustomFields1->customfield_value = "customfield_value";
$jsonCustomFields2->customfield_key = "customfield_key";
$jsonCustomFields2->customfield_value = "customfield_value";
// Create the JSON Object with the Email, Subcategories, and Custom Fields
// Email
$jsonObject->email = "Email To Update";
// Add the ID of the Subcategories into an Array to assign this Subscribers into the Subcategories
$jsonObject->subcategories = array();
// Custom Fields
$jsonObject->customfields = array($jsonCustomFields1, $jsonCustomFields2);
// Encode the Json Object into a String
$jsonEncoded = json_encode($jsonObject);
$options = array(CURLOPT_URL => $EngineMailerApiPath ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $jsonEncoded
);
curl_setopt_array($ch, $options);
// Calls the Rest API
$respone = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
echo $respone;
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}