0

UPDATE: I just noticed in the CloudWatch logs, that the content type has somehow mutated from application/json to text/plain. Here is what the WebHost string looks like now:

[Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting POST https://snip.execute-api.us-west-2.amazonaws.com/Stage/api/Clinician text/plain

This is what it looked like when the call was working:

[Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting POST https://snip.execute-api.us-west-2.amazonaws.com/Stage/api/Clinician application/json And yet, the header in Postman sets Content-Type: application/json

So why is the content type changing?

Beginning of original post:

I'm developing an API Gateway Lambda Function using Visual Studio 2017 "Serverless Application with Test" blueprint which is a .NET CORE solution. We are using Cognito User Pools for authentication. I am using Postman to test my first function. I'm passing a valid ID Token for a User in a Cognito User Pool. The request passes authentication but responds with a 415 Unsupported Media Type.

Before I started passing an ID Token, I was using AWS_IAM authorizer. At that time, the body (content-type: application/json) would map to the POST parameter successfully. But now that I am using the Cognito User Pool authorizer, I get a 415 Unsupported Media Type when calling POST. The POST method signature is:

    [HttpPost]
    public APIGatewayProxyResponse Post([FromBody]Clinician user)

The sample data I am sending in the body is:

{
"Id": "",
"Username": "6punk",
"Title": "Punker",
"FirstName": "Six",
"MIddleName": "",
"LastName": "Punk",
"Suffix": "",
"PreferredFirstName": "",
"PreferredLastName": "",
"Email": "[email protected]",
"Phone": "+18015551206",
"UserSub": "",
"ClinicianTypeId": "1",
"EhrId": ""

}

As already mentioned, when authenticating as an IAM user or when testing via the Method Test pane in the API Gateway Console, the JSON maps perfectly to the Clinician class.

I have CORS enabled. For the ANY method, I have the Integration Request type set to LAMBDA_PROXY.

Any ideas what is causing the 415 Unsupported Media Type when testing my POST method from Postman with an ID Token from a Cognito User?

1
  • Can you show the cURL code that Postman generates when you send that request? Commented Apr 20, 2018 at 15:16

1 Answer 1

0

As it turns out, it was a bug in Postman. Even though I had specified the Content-type as application/json, it was passing the content type as text/plain. I deleted the Content-Type header and then recreated it and things started working. I had had Postman up for several days. I don't know for certain why it started passing text/plain. All I know is that when I deleted and recreated the Content-Type header as application/json, only then did things start working again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.