Skip to content

Instantly share code, notes, and snippets.

@patrickisgreat
Last active July 17, 2019 20:36
Show Gist options
  • Save patrickisgreat/c1bda941da20e5c36282c6395223e040 to your computer and use it in GitHub Desktop.
Save patrickisgreat/c1bda941da20e5c36282c6395223e040 to your computer and use it in GitHub Desktop.
<?php
use ExactTarget\ET_Get;
use ExactTarget\ET_Client;
use ExactTarget\ET_Subscriber;
use Illuminate\Http\Request;
class TestController extends Controller
{
/**
* @return Response
*/
public function index()
{
return (new Response('Unauthorized', 401));
}
/**
* @param Request $request
* @param $key
* @return \Illuminate\Http\JsonResponse
*/
public function process(Request $request, $key)
{
if ($key != 'TestKeyNotReal') {
return (new Response('Unauthorized', 401));
}
$email = $request->input('email_address');
$email = trim($email);
$autoTraderClient = new ET_Client('AutoTrader', true, false, [
'clientid' => 'xxxxxxxxxxx',
'clientsecret' => 'xxxxxxxxxxxxx'
]);
// Create A Subscriber
$subCreate = new ET_Subscriber();
$subCreate->authStub = $autoTraderClient;
$subCreate->props = [
'EmailAddress' => $email,
'SubscriberKey' => $email,
'Lists' => ['ID' => 44]
];
$postResult = $subCreate->post();
// Patch an existing Subscriber's email
$subPatch = new ET_Subscriber();
$subPatch->authStub = $autoTraderClient;
$subPatch->props = [
'EmailAddress' => $email,
'SubscriberKey' => $email,
'Lists' => ['ID' => 44]
];
$patchResult = $subPatch->patch();
// Patch to set a subscriber to Active
$subPatch->authStub = $autoTraderClient;
$subPatch->props = [
'EmailAddress' => $email,
'SubscriberKey' => $email,
'Lists' => [
[
'ID' => 44,
'Status' => 'Active'
]
]
];
$patchResult = $subPatch->patch();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment