Sendgrid-php: Permission denied, wrong credentials when using sendgrid-php 6.0.0 on PHP 7.2.3

Created on 10 Mar 2018  Â·  10Comments  Â·  Source: sendgrid/sendgrid-php

Issue Summary

When attempting to call $sg->client->mail()->send()->post($mail); per the Quick Start in README.md, I'm receiving the error "Permission denied, wrong credentials". I have verified that the API key I am using is correct and also have tried creating new API keys.

Where it gets interesting is that if I downgrade the sendgrid-php library to version 5.0.0, I'm able to successfully send an email.

Any thoughts here would be helpful! Thanks

Steps to Reproduce

Run the code from the Quick Start in README.md.

Technical details

  • sendgrid-php Version: master 8db454e4b5674b545c207a162b64202b0d63259b (6.0.0) and 9fb94f6a068a6bd887fed665fc33efcd301db486 (5.0.0)
  • PHP Version: 7.2.3 on macOS 10.13.3 installed via Homebrew
easy work in progress bug

Most helpful comment

@thinkingserious I also receive a 401 when using php-http-client 3.9.2. It appears the problem might lie in Client.php around lines 192-196:

if (isset($headers)) {
    $headers = array_merge($this->headers, $headers);
} else {
    $headers = []; // If $headers is null, $this->headers never gets used in the request.
}

Should probably be changed to:

if (isset($headers)) {
    $headers = array_merge($this->headers, $headers);
} else {
    $headers = $this->headers; // If $headers is null, $this->headers will still be used in the request.
}

When this change is made, I'm able to successfully send email. I'm not too familiar with the library, so this might not be the best/correct place to solve the issue.

All 10 comments

Looks like downstream dependency is properly broken — 2 last patches have introduced different regressions, see https://github.com/sendgrid/php-http-client/commit/46dcffa8b1c3ff56acbb78124d9e1e37d70d8c30.

Workaround is to pin "sendgrid/php-http-client": "3.9.0"

@thedotedge makes sense. Thanks!

Correction: it's actually 3.8.0 that works, all subsequent versions are broken. I wonder if it even makes sense to depend on "sendgrid/php-http-client": "~3.7" in sendgrid/sendgrid-php if downstream is so unstable.

In fact, even API is broken after sendgrid/php-http-client update: sample code sendgrid()->client->mail()->send()->post($mail); that is supposed to return response object silently start returning itself 😞

@thedotedge Pinning to 3.9.0 introduced a notice (seen below), but 3.8.0 seems to do the trick. Thanks!

Notice: Object of class SendGrid\Client could not be converted to int in /Users/frank/<removed>/vendor/sendgrid/php-http-client/lib/Client.php on line 269

@thedotedge @fterrag

Please try php-http-client 3.9.2, that version should be good to go. Thanks!

@thinkingserious does it work for you? For me every request was returning 401.

@thinkingserious I also receive a 401 when using php-http-client 3.9.2. It appears the problem might lie in Client.php around lines 192-196:

if (isset($headers)) {
    $headers = array_merge($this->headers, $headers);
} else {
    $headers = []; // If $headers is null, $this->headers never gets used in the request.
}

Should probably be changed to:

if (isset($headers)) {
    $headers = array_merge($this->headers, $headers);
} else {
    $headers = $this->headers; // If $headers is null, $this->headers will still be used in the request.
}

When this change is made, I'm able to successfully send email. I'm not too familiar with the library, so this might not be the best/correct place to solve the issue.

@thedotedge,

It was working for me when using php-http-client directly. I believe @fterrag found the fix though. When we set $headers = [] we are overwriting the values coming from sendgrid-php. I'm fixing now with 3.9.3.

With Best Regards,

Elmer

Thanks again to everyone on this thread for helping get a fix pushed out quickly.

I have verified that this bug is fixed using 3.9.3 in sendgrid-php.

Thanks again!

Related to #585.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

micahwalter picture micahwalter  Â·  3Comments

mwsasser picture mwsasser  Â·  3Comments

Aubynj picture Aubynj  Â·  3Comments

KayakinKoder picture KayakinKoder  Â·  5Comments

Theolodewijk picture Theolodewijk  Â·  4Comments