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...
We have the same issue here. The other APIs are working fine.
We get this response:
{"errors":[{"field":null,"message":"access forbidden"}]}
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
@interwap
I have solved the issue in another way.
I have contacted support they told me to use the new api.
I have used something like this:
$sg = new \SendGrid("SG.XXXX");
$request_body = json_decode('[
{
"age": 25,
"email": "[email protected]",
"first_name": "",
"last_name": "User"
}
]');
try {
$response = $sg->client->contactdb()->recipients()->post($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
@interwap
Sorry, this should be it.
https://sendgrid.api-docs.io/v3.0/contacts/add-or-update-a-contact
@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:
$sg = new \SendGrid("SG.XXXX");
$request_body = json_decode('{"contacts":[{"email":"[email protected]"}]}');
try {
$response = $sg->client->marketing()->contacts()->put($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
It seems that the SDK examples needs to be updated with the new marketing resources vs. the legacy ones.
@interwap I just encountered the same issue, but was able to resolve it using the SDK with the following:
$sg = new \SendGrid("SG.XXXX");
$request_body = json_decode('{"contacts":[{"email":"[email protected]"}]}');try {
$response = $sg->client->marketing()->contacts()->put($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}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...
Most helpful comment
@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.