sendgrid-php: 403 forbidden post batch_id
Access Forbidden
Can not get batch ID throw api, response code is 403. Due some investigation, we found this ticket: https://github.com/sendgrid/sendgrid-csharp/issues/185. However it was not helpfull, since we have only one account and we pretty sure we use admin account.
Steps to Reproduce
$sendGrid = $this->getNewSendGrid();
$response = $sendGrid->client->mail()->batch()->post();
class SendGrid\Response#98 (3) {
public $_status_code =>
int(403)
public $_body =>
string(56) "{"errors":[{"field":null,"message":"access forbidden"}]}"
public $_headers =>
string(648) "HTTP/1.1 403 FORBIDDEN
Server: nginx
Date: Thu, 14 Jul 2016 03:37:02 GMT
Content-Type: application/json
Content-Length: 56
Connection: keep-alive
Access-Control-Allow-Methods: POST, OPTIONS
Access-Control-Max-Age: 21600
Access-Control-Expose-Headers: Link
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: AUTHORIZATION, Content-Type, On-behalf-of, x-sg-elas-acl
Content-Security-Policy: default-src https://api.sendgrid.com; frame-src 'none'; object-src 'none'
X-Content-Type-Options: nos"...
}
Technical details:
- sendgrid-php Version: master (latest commit: [commit number])
- PHP Version: 5.x
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 21 (6 by maintainers)
I have to publicize this, because I don’t understand why 1) this is not documented, 2) we are being redirected to Support even though this is probably a known defect.
Here is the support response:
In an effort to be helpful, here’s what I just learned from connecting the dots across several SendGrid documentation pages, the most helpeful of which was this one.
PATCHrequest, but rather aPUT. This meant, I needed to firstGETthe existingscopesand then append the new ones. Otherwise, it overwrites all the existing scopes. Side note: whoa! It would be nice to supportPATCHhere, or make the dangerzone more clear in the docs.echo -n "<username>:<password>" | openssl base64curl -H "Authorization: $base64creds"nameof the API key, even if it already has one.PUTweb request to/v3/api_keys/<your key>{your_api_key}value is the second part. I.e. do not use thenameand do not send the entire key value.API v3 does accept Basic Auth.
Basically you need to set a header with something like:
"Authorization: Basic " . base64_encode("$username:$password")Where $username & $password belong to the main user. Including that header you will be able to use the endpoint api_keys/ to set the permissions
Request #716584
I have a API key with all the possible permissions and I got “access frobidden” when posting to the endpoint “mail/batch”. I’m using CURL.
I haven’t found an answer in the documentation/support forum
@papaben I guess you meant to write “it overwrites all the existing scopes” instead of “it overwrites all the existing keys”, didn’t you?
Thanks for the feedback @gsusI, I will put in a request with our documentation team.
And @oytuntez is very right, it should be documented properly to avoid this thread (and its duplicates) to keep growing.
Did that as well, thank you.
Oytun Tez
M O T A W O R D *- The World’s Fastest Human Translation Platform. *J S O N - L A N G - JSON specification for localization file exchange. I AM A FACT - Entrepreneurification!
On Thu, Jul 28, 2016 at 5:55 PM, Elmer Thomas notifications@github.com wrote:
The issue for me seems to be that not all the permissions allowed can be managed through the UI.