Skip to content

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

Closed
@jshergal

Description

@jshergal

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: help wantedrequesting help from the communitytype: questionquestion directed at the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions