sendgrid / sendgrid-php

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

Api POST /senders not working #1043

Closed Pyotor closed 3 years ago

Pyotor commented 3 years ago

Issue Summary

There is an issue with API POST /senders We are receiving an error. on-behalf-of was a teammate account which has a full permission to API Key

Code Snippet

$data = json_encode([
            'nickname' => 'Example Nickname',
            'from' => [
                'email' => 'example@gmail.com',
                'name' => 'Example Name'
            ],
            'reply_to' => [
                'email' => 'example@gmail.com',
                'name' => 'Example Name'
            ],
            'address' => 'N/A',
            'city' => 'N/A',
            'country' => 'N/A',
        ]);
        $headers = [
            "authorization: Bearer <<MY-API-KEY>>",
            "content-type: application/json",
            "on-behalf-of: areggrig"
        ];
        $curl = curl_init();
        curl_setopt_array($curl, array(
          CURLOPT_URL => "https://api.sendgrid.com/v3/senders",
          CURLOPT_RETURNTRANSFER => true,
          CURLOPT_ENCODING => "",
          CURLOPT_MAXREDIRS => 10,
          CURLOPT_TIMEOUT => 30,
          CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
          CURLOPT_CUSTOMREQUEST => "POST",
          CURLOPT_POSTFIELDS => $data,
          CURLOPT_HTTPHEADER => $headers,
        ));
        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);

log here


{#178
  +"errors": array:1 [
    0 => {#1816
      +"field": null
      +"message": "authorization required"
    }
  ]
}
thinkingserious commented 3 years ago

Hello @Pyotor,

Thanks for submitting a GitHub issue! We are very sorry that you are running into this problem. In order to better serve you, as this does not present itself as a library specific issue, we would like to ask that you reach out to our support team at https://support.sendgrid.com.

Thank you!

SendGrid DX Team