424
Views
23
Comments
Solved
REST - 415 Unsupported Media Type
Question


Hey everyone, hope you're all doing well.


I am currently consuming a rest API. It takes in five headers and a JSON body request.

One of the headers is to define the Content-Type to JSON.

When testing on the REST API screen, it successfully returns the call with no errors (See below).


I then proceed to put this API call into a server action. I define the headers and pass in a JSON Body request (same ones as the one I tested on the test screen). The JSON request has been deserialized into the correct structure. Whilst debugging, the deserialized JSON object has all the correct values (same as the test).

However, whenever this server action is called, I get 415 Unsupported Media Type error (again the header has been defined as JSON).

If anyone could point out what I am doing wrong, that would be grateful. Please feel free to ask for more info if needed.

Many thanks in advance,

Suhail


(Edit: wrong image included)


Rank: #8842
Solution

Hi Leandro / everyone,


Thanks for the reply.

I talked with the API devs and they advised that the reason I was getting the errors was due to the addition of the charset in the content-type header 

(pic from earlier post)

They said they'll work on the API so the call can be made without any errors.

Thank you all for your efforts. Greatly appreciated.


Thanks,

Suhail

Rank: #140

Suhail Patel wrote:


Hey everyone, hope you're all doing well.


I am currently consuming a rest API. It takes in five headers and a JSON body request.

One of the headers is to define the Content-Type to JSON.

When testing on the REST API screen, it successfully returns the call with no errors (See below).


I then proceed to put this API call into a server action. I define the headers and pass in a JSON Body request (same ones as the one I tested on the test screen). The JSON request has been deserialized into the correct structure. Whilst debugging, the deserialized JSON object has all the correct values (same as the test).

However, whenever this server action is called, I get 415 Unsupported Media Type error (again the header has been defined as JSON).

If anyone could point out what I am doing wrong, that would be grateful. Please feel free to ask for more info if needed.

Many thanks in advance,

Suhail


(Edit: wrong image included)


Hi Suhail,

Please refer below link

https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Extensibility_and_Integration/REST_APIs/Exposed_REST_API/Supported_Media_Types_in_REST_API_Requests

Hope this will help :)

Regards,

Amit



Rank: #260

Suhail,


Could you check your messagebody and header in the on before request event?

If you can submit that result over here, maybe we can see why it is sending 415.


Edit:

Your consumed post Rest should look like this:


Rank: #260

Your request body is empty? 

-> {}

Rank: #260

This JSON looks fine to me.


Now can you add the onafterresponse event and debug that returnmessage?

Maybe you get more information from it.

Rank: #260

This is strange since you should get the 415 in the on after response.



Rank: #260

Could you check the ... of the ResponseText?

There seems to be a lot of empty space there, but not empty.

Rank: #260

I am not sure but i think the problem is the accept of the exposing service. I think its not set to application/JSON.


Ofcourse i am not sure but if thats not the case, i think we need help from other users over here ;)


Another thing:  I see double "" for each of your request items. But in the response i don't see them. Could this be the problem?

Rank: #260

So, with this adjustment your API now works ok?


This means we have found the problem. If you want to use the " instead of the ': this is possible but you need to check carefully. Each " must be doubled and when combining with variables you need 3 in a row. I think you missed one or two. Those are common errors.

mvp_badge
MVP
Rank: #163

Hi Stefano,

Maybe it is related to encoding, can you confirm what is the encode used on the API it is the same on OutSystems (utf-8)?

Besides that, you can verify if there is some invalid character in the JSON content.

Font: https://www.keycdn.com/support/415-unsupported-media-type

mvp_badge
MVP
Rank: #163

Another tip, verify in the API log what's happening on the request processing.

Rank: #8842
Solution

Hi Leandro / everyone,


Thanks for the reply.

I talked with the API devs and they advised that the reason I was getting the errors was due to the addition of the charset in the content-type header 

(pic from earlier post)

They said they'll work on the API so the call can be made without any errors.

Thank you all for your efforts. Greatly appreciated.


Thanks,

Suhail

Rank: #260

I didnot expect this because it worked in Test. Shouldn't Test have the same headersettings?

Overwrite content-type header at OnBeforeRequest. 

It worked for me.