<?php
// Subscribe to Omnisend, copyright 2019-2020, Silver Dolphin Solutions, LLC, Ed Lemmers
// For licensing, see license.txt.
//
require_once __DIR__ . "/Omnisend.php";
include_once("api_keys.php");

//$display_results = true;
$country = "United States";

//change 'your-api-key' to you're API Key
$omnisend = new Omnisend(OMNISEND_API_KEY, array('timeout' => 15));

$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];

// Create new contact
$contactID = "";
$contacts = $omnisend->post(
    'contacts',
    array(
        "email" => $email,
        "firstName" => "$first_name",
        "lastName" => "$last_name",
        "status" => "subscribed",
		"statusDate" => date("Y-m-d\TH:i:s+00:00"),
    )
);
if ($contacts && $display_results) {
    print_r($contacts);
    $contactID = $contacts['contactID'];
} else {
    print_r($omnisend->lastError());
}

// updated in example 1 created contact
if ($contactID) {
    $contacts = $omnisend->patch(
        'contacts/' . $contactID,
        array("country" => "United Kingdom")
    );
    if ($contacts && $display_results) {
        print_r($contacts);
    } else {
        print_r($omnisend->lastError());
    }
}
?>