sendgrid-csharp: Contacts API fails with Content-Type application/json; charset=utf-8
Making a request to the Contacts API endpoint ({baseUrl}/marketing/contacts) with a Content-Type of application/json; charset=utf-8 returns a 400 Bad Request saying that the content type is not supported:
{
"errors": [
{
"field": "content-type",
"message": "invalid content-type: application/json; charset=utf-8"
}
]
}
You can try it out yourself at https://sendgrid.com/docs/API_Reference/api_v3.html and send a PUT request to the Contacts endpoint.
Unfortunately this C# client ALWAYS sets the charset to UTF8, which makes it unusable for some endpoints like the one above. Can the SendGrid folks please accept the entirely valid media type with the charset or at least make it optional in the RequestAsync method of the client?
Feels really broken right now and is frustrating that I’ve spend a couple hours trying to understand why a valid request gets denied for appending the charset -.-
If I send the same request with just application/json (without the utf-8 charset) then the request succeeds, but that has to be done manually and can’t be done with the RequestAsync method at the moment.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 10
- Comments: 21 (6 by maintainers)
Commits related to this issue
- #910 Remove char set from content headers — committed to marius-stanescu/sendgrid-csharp by deleted user 7 years ago
I can’t believe this is an issue nearly four months after being reported.
For a hack, add this on line 231 of SendGridClient.cs:
if (request.Content != null) { request.Content.Headers.ContentType.CharSet = string.Empty; }I have no idea if this breaks any other API calls.
This needs to be fixed on your server. It doesn’t seem like an earth shattering change. Why has it not been addressed? The fact that API calls fail with your own client is unacceptable.
@dustinmoris Yes, this repo is part of Twilio SendGrid, but issues here are only monitored by the engineering team responsible for managing the repo itself. For account, request, and API-specific issues, only support is able to help.
@childish-sambino Are you guys not working for the same company? Is https://github.com/sendgrid/sendgrid-csharp not part of the company SendGrid? If it is, then consider this issue the support ticket. If it’s in the wrong repo then please move it into the correct (private?) repo where it belongs?
@dustinmoris and @hallidev make a good point. Paying customers should not be told to find the appropriate support person within an organisation. Departments within an organisation should not tell paying customers ‘not my problem’. If paying customers raise an issue, getting that issue fixed should not be the customer’s problem.
I see this time and again on this repo and it is not a good look for Twilio/SendGrid
Sorry to bother you again, I know this is fixed on the CSharp lib. But I am using the bare minimum with axios for js and I am facing the same issue. So the problem is not on the client (axios for js neither the csharp client). Please reconsider moving this to a backend issue. pls refer to https://datatracker.ietf.org/doc/html/rfc8259
Correct me if I am wrong but the sendgrid servers should accept charset. For now, I am going to hardcode this fix, but given others might face the same issue, pls re-open the issue.
Here goes a similar discussion but for axios https://github.com/axios/axios/issues/2154
@childish-sambino I’m wondering the same thing. Isn’t this Sendgrid’s official client for C#?