Skip to content

Receiving "UnsupportedMediaType" error just trying to use the simple example code with v8.0.4 #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jshergal opened this issue Aug 31, 2016 · 3 comments
Labels
status: help wanted requesting help from the community type: question question directed at the library

Comments

@jshergal
Copy link

jshergal commented Aug 31, 2016

Issue Summary

I was just trying to test out the new version and upgrade to the newer 3.0 code sample (was using the older 6.0 series library and so had to rewrite the code). All I wanted to do was verify the simple example worked and I keep getting "UnsupportedMediaType" errors. Here is the code I am testing. I was running it in LINQPad 5.0.8.1 and .Net 4.6.

Note
I did try changing the "Content" line to "text/html" and "application/json" and still received the same error so I am assuming there is something else going awry here.

var fromAddress = new Email("[email protected]", "MyCompanySupport");
var content = new Content("text/plain", "This is a test email.");
var mail = new Mail(fromAddress, "Testing Email", new Email("[email protected]"), content);
dynamic sgc = new SendGridAPIClient("MYAPIKEYREMOVEDFROMTHESAMPLE");
dynamic response = await sgc.client.mail.send.post(reqestBody: mail.Get());
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());

Output:
UnsupportedMediaType
{"errors":[{"message":"Content-Type should be application/json.","field":null,"help":null}]}
Connection: keep-alive
X-Frame-Options: DENY
Date: Wed, 31 Aug 2016 21:59:38 GMT
Server: nginx

VS 2015 Console APP code
I wanted to be sure I gave a pure test as well. This is the code from a VS2015 Console APP targeting .Net 4.5.2 with the latest SendGrid (v8.0.4) added to the project via NuGet. I can upload the project if that would prove helpful.

using SendGrid;
using SendGrid.Helpers.Mail;
using System;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        const string SendGridApiKey = "MYSENDGRIDAPIKEY";

        static void Main(string[] args)
        {
            SendMail().Wait();
            Console.ReadLine();
        }

        private static async Task SendMail()
        {
            var fromAddress = new Email("[email protected]", "MyCompanySupport");
            var content = new Content("text/plain", "This is a test email.");
            var mail = new Mail(fromAddress, "Testing Email", new Email("[email protected]", "Jeff"), content);
            dynamic sgc = new SendGridAPIClient(SendGridApiKey);
            dynamic response = await sgc.client.mail.send.post(reqestBody: mail.Get());

            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.Body.ReadAsStringAsync().Result);
            Console.WriteLine(response.Headers.ToString());
        }
    }`
}

The result was the same as the previous mentioned output.

@thinkingserious thinkingserious added type: question question directed at the library status: help wanted requesting help from the community labels Sep 1, 2016
@thinkingserious
Copy link
Contributor

Hello @jshergal,

reqestBody should be requestBody

With Best Regards,

Elmer

@jshergal
Copy link
Author

jshergal commented Sep 3, 2016

@thinkingserious - Thank you! I totally missed that. Another plug for moving away from dynamic so that the compiler would catch those type of typos.

@thinkingserious
Copy link
Contributor

@jshergal,

Thanks, I've added your vote to this ticket: #303

gabrielkrell pushed a commit to gabrielkrell/sendgrid-csharp that referenced this issue Aug 2, 2017
gabrielkrell pushed a commit to gabrielkrell/sendgrid-csharp that referenced this issue Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

2 participants