sendgrid / sendgrid-php

The Official Twilio SendGrid PHP API Library
https://sendgrid.com
MIT License
1.49k stars 624 forks source link

Can't send a campaign #1016

Closed quentint closed 3 years ago

quentint commented 3 years ago

Issue Summary

Sending a campaign using the "sendgrid/sendgrid ^7.8" PHP API.

Steps to Reproduce

I tried lots of variations of API calls, including:

But none of them worked.

Technical details:

Also: I noticed I can't use your docs because everything seems off (different method chaining, different parameters). Where can I find the proper docs (for ^7.8)?

Thanks in advance.

Note: I opened a support request on support.sendgrid.com (#5288817) but got no answer 🙁

childish-sambino commented 3 years ago

The first example was close, but it needs to include a time to send at value (UNIX timestamp for the date and time you would like your campaign to be sent out). E.g.,:

$sg->client->campaigns()->_($campaignId)->schedules()->post(['send_at' => 1489771528]);

Or just send now:

$sg->client->campaigns()->_($campaignId)->schedules()->now()->post();
quentint commented 3 years ago

Thanks @childish-sambino, I've tried your second snippet (I'm trying to send now), but I get a 403 with {"errors":[{"field":null,"message":"access forbidden"}]}. All my other calls are OK (so I guess the API key, a Full Access one, is good).

The other places in my code where I successfully use the campaigns API is by using $this->sg->client->marketing()->campaigns()->post($request) (note the extra ->marketing()).

Of course I tried $this->sg->client->marketing()->campaigns()->_($campaignId)->schedules()->now()->post(); bot got a 404 🙁

Any idea? Could my API key (or account) be insufficient for sending/scheduling campaigns?

childish-sambino commented 3 years ago

Docs there may help: https://sendgrid.api-docs.io/v3.0/single-sends

Example:

$response = $sg->client->marketing()->singlesends()->_($campaignId)->schedule()->put(['send_at' => 'now']);
quentint commented 3 years ago

Wow, it works! Thanks very much!

I have two questions:

childish-sambino commented 3 years ago