Error 415 Unsupported Media Type for GET method

4.7k Views Asked by At

I'm currently working through the Mulesoft Mule 4 Fundamentals course and have deployed an application on Runtime Manager.

When I look in the logs of my application on Runtime Manager and the logs of Anypoint Studio I see the above "Unsupported Media Type" error when testing a GET HTTP request. I also get this error when testing in ARC.

When I look in the Mule debugger and then the payload in Anypoint Studio I see mediaType = */* charset = UTF-8

I thought that this does not need to be added for GET requests, so how do I get around this?

My RAML file:

#%RAML 1.0
title: session-2

types:
  newsProperties: !include schemas/newsDataType.raml

/search:
  get:
    headers:
      Accept:
        default: application/json
    queryParameters:
      keyword:
        type: string
        minLength: 3
        maxLength: 10
    responses:
      200:
        body:
          application/json:
            example: !include examples/searchExample.raml
      400:
        body:
          application/json:
            example:
              {"message": "Search query too long"}
/news:
  post:
    queryParameters:
      country:
        required: false
    body:
      application/json:
        type: newsProperties
    responses:
      201:
        body:
          application/json:
            example: !include examples/searchExample.raml

/sportsNews:
  put:
    body:
      application/json:
        type: newsProperties

The header in the /search resource GET method has been added recently after searching online and trying a number of different solutions I've seen, but I am still getting the same error. Any help would be appreciated.

5

There are 5 best solutions below

2
On

You can solve this error by renaming the endpoint generated by the apiKit.

Original Flow Name:

get:\worker**:application\json:**prueba-sapi-config

Revised Flow Name:

get:\worker:cs-prueba-sapi-config

With this adjustment, it is no longer necessary to specify the Content-Type.

3
On

I had this same problem and I solved it by mapping the endpoint on Router (apikit:config). Then I figured out the name set to the router was different on the endpoint flow, like:

  • Flow name: get:(userId):api-config
  • Router name: users-api-config

Fixing the name on flow or mapping the method on router solve this problem

2
On

Probably you are not setting the Content-Type header to application/json and the API implementation is expecting it.

0
On

Hello try to include a json example instead a raml example:

!include examples/searchExample.raml convert it to include json example.

!include examples/searchExample.json

0
On

I have faced the same issue due to a name mismatch on my router and application-interface. If you're using an application interface as a reference for all flows in your application, make sure that you're using same naming on the router config and each endpoint referred on the interface. Something like...

<apikit:router doc:name="APIkit Router" config-ref="api-config" /> 

for your router and

<flow name="get:\users:api-config" 

on your interface.