1

So i'm trying to track if an email returns a bounce (address not found)

Here's my code:

#Find bounce report.
$curl = curl_init();

curl_setopt_array($curl, 
array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLAUTH_ANY,
    CURLOPT_URL => 'https://api.sendgrid.com/v3/suppression/bounces/'.$bouncemail.'/',
    CURLOPT_HEADER => 'Authorization: Bearer <<REDACTED>>'
));

$bounce_report = curl_exec($curl);
curl_close($curl);

I can't seem to find what i'm doing wrong here.

This is what i get:

authorization required

Maybe some of you can see it?

Kind regards

Napoli
  • 1,389
  • 2
  • 15
  • 26

2 Answers2

0

You probably want

CURLOPT_HTTPHEADER

instead of

CURLOPT_HEADER

as CURLOPT_HEADER is for allowing HEADERS to be returned or not while CURLOPT_HTTPHEADER is what is sent with the request.

Virre
  • 134
  • 1
  • 8
  • Hey! Sorry for the late answer, just returned from weekend.. I was thinking about that, but that ain't working either.. It still says the same. Thanks for the comment tho! :D –  Oct 01 '18 at 07:04
  • Okey, I have some more thoughts about not using request methods (you probably want todo a post request). But I think looking into the answers to this question will help more https://stackoverflow.com/questions/30426047/correct-way-to-set-bearer-token-with-curl – Virre Oct 01 '18 at 07:51
0

Your API Key has restricted access. To give it elevated privileges

Go To :

SendGrid Dashboard > Settings > API Keys > Edit Api Key > Give Full Access to Key > Update

Api Management Console

Dharman
  • 30,962
  • 25
  • 85
  • 135
Shivam Anand
  • 952
  • 1
  • 10
  • 21