Skip to content

Instantly share code, notes, and snippets.

@cheey2003
Created September 24, 2014 06:54
Show Gist options
  • Save cheey2003/562536d5186b9083fb54 to your computer and use it in GitHub Desktop.
Save cheey2003/562536d5186b9083fb54 to your computer and use it in GitHub Desktop.
REST API to Update Custom Fields in Eloqua
<?php
// include the Eloqua REST client
include_once('eloquaRequest.php');
// Declare Public Classes for Field Values & Contacts
class fieldValues {
public $type;
public $id;
public $value;
}
class Contact {
public $address1;
public $address2;
public $address3;
public $businessPhone;
public $city;
public $country;
public $emailAddress;
public $firstName;
public $id;
public $lastName;
public $isSubscribed;
public $isBounceback;
public $salesPerson;
public $title;
}
// Declare the New Field Values in Array
$fieldValues[0] = new fieldValues;
$fieldValues[0]->type = "FieldValue";
$fieldValues[0]->id = 100279; // C_Payroll_Hub_Report_1_PDF1
$fieldValues[0]->value = "http://google.com";
$fieldValues[1] = new fieldValues;
$fieldValues[1]->type = "FieldValue";
$fieldValues[1]->id = 100280; // C_Payroll_Hub_Report_2_PDF1
$fieldValues[1]->value = "http://google.com";
// Search the Eloqua Database based on Email Address and Display the Result
$contact = new Contact();
$contact->emailAddress = "patrick.tang@ngahr.com";
$client = new EloquaRequest('sitename', 'username', 'password', 'https://secure.eloqua.com/API/REST/2.0');
$query_data = $client->get("/data/contacts?search='" . $contact->emailAddress . "'&depth=complete");
print_r ($query_data);
// Get the ID of the First Result, Populate the Required & Custom Fields and Display the Result (bug:some contact fields will be empty if not re-populated)
$contact->id = $query_data->elements[0]->id;
$contact->firstName = $query_data->elements[0]->firstName;
$contact->lastName = $query_data->elements[0]->lastName;
$contact->country = $query_data->elements[0]->country;
$contact->accountName = $query_data->elements[0]->accountName;
$contact->title = $query_data->elements[0]->title;
$contact->address1 = $query_data->elements[0]->address1;
$contact->address2 = $query_data->elements[0]->address2;
$contact->address3 = $query_data->elements[0]->address3;
$contact->businessPhone = $query_data->elements[0]->businessPhone;
$contact->city = $query_data->elements[0]->city;
$contact->salesPerson = $query_data->elements[0]->salesPerson;
$contact->fieldValues = $fieldValues;
print_r ($contact);
print "<br><br>";
$import_data = $client->put("/data/contact/" . $contact->id, $contact);
print "Import data response:<br>";
print_r ($import_data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment