Skip to content

Instantly share code, notes, and snippets.

@neilbradley
Last active May 25, 2017 14:22
Show Gist options
  • Save neilbradley/19a74b0f82e9587fb27f7f60358a8d8d to your computer and use it in GitHub Desktop.
Save neilbradley/19a74b0f82e9587fb27f7f60358a8d8d to your computer and use it in GitHub Desktop.
Dotmailer Add Transactional Data
<?php
//https://developer.dotmailer.com/docs/add-transactional-data-to-contact
//PHP Version 7 Example
$apiUsername = "API_USER"; //Your API username
$apiPassword = "API_PASSWORD"; //your API password
$baseUrl = 'https://r1-api.dotmailer.com';
$url = $baseUrl . '/v2/contacts/transactional-data/Orders';
$content = [
'key' => 'ORDER_ID',
'contactIdentifier' => 'EMAIL_ADDRESS',
'json' => json_encode([
"PurchaseDate" => "2017-05-16T10:01:21Z",
"TotalExTax" => 140.83,
"TotalIncTax" => 169.00,
"Product" => [
"Name" => "The O Ultimate Set",
"Brand" => "Cloud Nine",
"Department" => "Hair",
"Category" => "Curlers",
"PriceExTax" => 140.83,
"ProductID" => "UK-THEO-GIFTSET-BLACK"
],
"SalesChannel" => "In store",
"SalesSubChannel" => "Cloud Nine - UK"
])
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch, CURLOPT_HTTPHEADER, array('Accept: application/json',
'Content-Type: application/json')
);
curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST);
curl_setopt(
$ch, CURLOPT_USERPWD,
$apiUsername . ':' . $apiPassword
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($content));
$response = json_decode(curl_exec($ch));
//PHP Version 5.3.29 Example
$apiUsername = "API_USER"; //Your API username
$apiPassword = "API_PASSWORD"; //your API password
$baseUrl = 'https://r1-api.dotmailer.com';
$url = $baseUrl . '/v2/contacts/transactional-data/Orders';
$content = array(
'key' => 'ORDER_ID',
'contactIdentifier' => 'EMAIL_ADDRESS',
'json' => json_encode(array(
"PurchaseDate" => "2017-05-16T10:01:21Z",
"TotalExTax" => 140.83,
"TotalIncTax" => 169.00,
"Product" => array(
"Name" => "The O Ultimate Set",
"Brand" => "Cloud Nine",
"Department" => "Hair",
"Category" => "Curlers",
"PriceExTax" => 140.83,
"ProductID" => "UK-THEO-GIFTSET-BLACK"
),
"SalesChannel" => "Online",
"SalesSubChannel" => "Cloud Nine - UK"
))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch, CURLOPT_HTTPHEADER, array('Accept: application/json',
'Content-Type: application/json')
);
curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST);
curl_setopt(
$ch, CURLOPT_USERPWD,
$apiUsername . ':' . $apiPassword
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($content));
$response = json_decode(curl_exec($ch));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment