sendgrid / sendgrid-csharp

The Official Twilio SendGrid C#, .NetStandard, .NetCore API Library
https://sendgrid.com
MIT License
1.08k stars 586 forks source link

Using Sendgrid API from C# throwing an error "UnAuthrized" and "Http verb GET does not support body" #1146

Closed ops-mamdouh closed 2 years ago

ops-mamdouh commented 2 years ago

Hi There,

I am trying to get the Bounces from Sendgrid, I followed below two documentations:

Testing the API using "try it" on doc site works. but using the same code from your site doesn't

Not sure what I am missing, I spoke to support agent, he tried till reached his limit and advised to open ticket here.

Here is snippet of my code code

Here are the errors form both code samples: err 1 err2

Here is the values from Debug mode: param 1 param 2

Thanks,

ops-mamdouh commented 2 years ago

It worked with me by removing this line: request.AddParameter("application/json", "{}", ParameterType.RequestBody);

Full working code: var client = new RestClient("https://api.sendgrid.com/v3/suppression/bounces"); var request = new RestRequest(Method.GET); request.AddHeader("content-type", "application/json"); request.AddHeader("accept", "application/json"); request.AddHeader("authorization", SendGridAPIKey); IRestResponse response = client.Execute(request);