-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs needed for new marketing campaign APIs #896
Comments
We have the same issue here. The other APIs are working fine. We get this response: |
Hi @dswmedia apparently, using the SDK's subscribe method doesn't work right out the box for version 2. You may have to use the rest API. I, however, had to pay to get the legacy contacts activated on my account then subscription started working. Contact support to activate legacy marketing |
I have solved the issue in another way. I have used something like this:
|
Sorry, this should be it. |
@dswmedia yes, this is via the API... but not using the Sendgrid SDK. I'd imagine that the point of even using the SDK at all is so we don't get to write curl requests ourselves. |
@interwap I just encountered the same issue, but was able to resolve it using the SDK with the following:
It seems that the SDK examples needs to be updated with the new marketing resources vs. the legacy ones. |
Thanks, will test that out |
I'll review a PR to update the docs if anyone wants to create it. |
bah.. just spent an hour to fix the legacy error... |
Yeah, new docs need to be created. I just lost an hour trying to figure out why postman works and the library does not. I would suggest SendGrid add a disclaimer line and a link to this issue in the docs. That would save a lot of time! |
I figured out adding pretty easily. However deleting was much more of a pain than it needed to be. Add a little defensive programing to this and you should be golden. This library has been frustrating to work with. private SendGrid $emailProvider; Add public function addContacts(array $users): void
{
$contacts = array_map(
function (array $user): array
{
return [
'email' => $user['email'],
'first_name' => $user['firstName'],
'last_name' => $user['lastName'],
"unique_name" => $user['username'],
];
},
$users
);
$this->emailProvider->client->marketing()
->contacts()
->put(['contacts' => $contacts]);
} Delete /**
* @psalm-suppress UndefinedMagicMethod
*/
public function removeContacts(array $emails): void
{
$request = ['emails' => $emails];
/** @var string $response */
$response = $this->emailProvider->client->marketing()
->contacts()
->search()
->emails() //magic method
->post($request)
->body();
$results = json_decode($response, true);
$emailIds = [];
foreach ($results['result'] as $contact) {
if (isset($contact['contact'])) {
$emailIds[] = $contact['contact']['id'];
}
}
$this->emailProvider->client->marketing()
->contacts()
->delete(null, [
'ids' => implode(',', $emailIds)
]);
} |
I'm trying to add a recipient(s) to a list using the PHP SDK but it doesn't seem to work. I get hit with the unauthorized access error (403). Funny thing is I'm even on a paid plan, changed API keys but all to no avail. Sending emails works fine but I can't get a subscription to work.
I contacted support with my issue and I was told they don't do that kind of diagnosis and will have to leave a message here on git. smh...
The text was updated successfully, but these errors were encountered: