Serverless Function POST returning 415 - Incorrect media type

Have a very simple POST serverless function that was working perfectly up until this morning. It receives a body in json format. When hitting the function, it immediately returns with an error 415 incorrect media type. I have double checked the content-type header = application/json but it’s not backing down - doesn’t even get into my function.

"message": "Request failed with status code 415",
 "name": "Error",
 "stack": "Error: Request failed with status code 415\n at createError (/var/task/src/webpack:/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/var/task/src/webpack:/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.<anonymous> (/var/task/src/webpack:/node_modules/axios/lib/adapters/http.js:260:11)\n at IncomingMessage.emit (events.js:326:22)\n at IncomingMessage.EventEmitter.emit (domain.js:483:12)\n at endReadableNT (_stream_readable.js:1241:12)\n at processTicksAndRejections (internal/process/task_queues.js:84:21)",
 "config": {
 "url": "https://www.ikhokha.com/_hcms/api/ikshopcallbackv2?draftorderid=gid://shopify/DraftOrder/869843697722",
 "method": "post",
 "data": "{\"transactionId\":\"test\",\"status\":\"SUCCESS\",\"responseCode\":\"00\",\"responseMessage\":\"Successful\"}",
 "headers": {
 "Accept": "application/json, text/plain, */*",
 "Content-Type": "application/json",
 "ik-appid": "---",
 "ik-sign": "---",
 "User-Agent": "axios/0.21.1",
 "Content-Length": 94
 },
 "transformRequest": [
 null
 ],
 "transformResponse": [
 null
 ],
 "timeout": 0,
 "xsrfCookieName": "XSRF-TOKEN",
 "xsrfHeaderName": "X-XSRF-TOKEN",
 "maxContentLength": -1,
 "maxBodyLength": -1
 }
}

Strange that it suddenly stopped working. :thinking:

@John , do you have any thoughts on this?

Is the payload is in json format, if not stringify it. How does this post request run in Postman? You getting the same error?

Thanks Dennis and John, I tried again this morning and never got the 415 - didn’t change anything my side so not sure why. What I did notice was that the stringified json body was not being automatically parsed, so I converted it first using JSON.parse(context.body) in the top of the function and then was able to continue.