Hi there
I am successfully creating a contact via an API call. I now want to add that created contact to a existing target list. Here is what I have so far:
public function subscribe(Request$request)
{
try {
$client = newClient('https://mywebsite.com');
$client->setApiKey('xxxx);
// Validate input
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|max:255',
]);
// Split full name into first and last name
$fullName = trim($request->name);
$parts = explode(' ', $fullName, 2);
$firstName = $parts[0];
$lastName = $parts[1] ?? '?';
// 1. Create the contact
$contactResponse = $client->request(Client::METHOD_POST, 'Contact', [
'firstName' => $firstName,
'lastName' => $lastName,
'emailAddress' => $request->email,
'cType' => 'Guest',
]);
// 2 Here I want to add the created contact to a target list but I cannot find documentation for it. Please help.
} catch (\Throwable$e) {
$message = $e->getMessage();
returnresponse()->json([
'error' => 'Subscription failed.',
'message' => $message,
], 500);
}
}
Thanks
Jacques zz0.x0pm5t1iy6zz
I am successfully creating a contact via an API call. I now want to add that created contact to a existing target list. Here is what I have so far:
public function subscribe(Request$request)
{
try {
$client = newClient('https://mywebsite.com');
$client->setApiKey('xxxx);
// Validate input
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|max:255',
]);
// Split full name into first and last name
$fullName = trim($request->name);
$parts = explode(' ', $fullName, 2);
$firstName = $parts[0];
$lastName = $parts[1] ?? '?';
// 1. Create the contact
$contactResponse = $client->request(Client::METHOD_POST, 'Contact', [
'firstName' => $firstName,
'lastName' => $lastName,
'emailAddress' => $request->email,
'cType' => 'Guest',
]);
// 2 Here I want to add the created contact to a target list but I cannot find documentation for it. Please help.
} catch (\Throwable$e) {
$message = $e->getMessage();
returnresponse()->json([
'error' => 'Subscription failed.',
'message' => $message,
], 500);
}
}
Thanks
Jacques zz0.x0pm5t1iy6zz
Comment