168
Views
9
Comments
Consuming rest api - bad request 400

I have declared the content-type however I am still getting this message:
"Header missing: please add content-type: application/json or application/ejson to specify payload data types" in the error log.




2019-07-01 07-16-04
Vinod Patidar

Hi Shum,

Please check ContentType Parameter value, you are passing text/plain and API required application/json.

Thanks

Vinod

UserImage.jpg
Shum Chin Ning

Hi vinod,


I have passed the content-type as application/json via site properties (Site.ContentType)


snippet from site properties:


2016-04-22 00-29-45
Nuno Reis
 
MVP

Hi.

I can only see the action you are calling and that is fine. But the error is on the API call, not on OutSystems. 

You need to set the headers here, on the method:

Is that section ok?

UserImage.jpg
Shum Chin Ning

Hi 

I have declared the content type inside the method and assigned it using site properties (in my previous reply)

2016-04-22 00-29-45
Nuno Reis
 
MVP

Considering we don't know what API you are calling, it can be case sensitive or something unexpected.

I would try it in Postman and when it works, copy the exact configuration/format into the OS method.

UserImage.jpg
Shum Chin Ning

I am actually calling mongodb atlas data api to update a document in the database (https://www.mongodb.com/docs/atlas/api/data-api-resources/#update-a-single-document). 

I have consumed the api to read items from mongodb (and there were no issues ) but when i use the api to update items,  it throws me the header error even though i have declared it. I have tested it in postman and it works fine. 


2016-04-22 00-29-45
Nuno Reis
 
MVP

The headers that correspond to the documentation seem to match. Are the others needed?

Doesn't make sense that it works on Postman and the same here doesn't.



UserImage.jpg
Shum Chin Ning


I tried to remove the additional headers , but it's still throwing me the same error. 

2022-07-24 08-50-37
Gokula Kannan P

Hi @Shum Chin Ning,

As Nuno said you are passing the parameter to server action but it's not properly mapped with the Rest Consume Method.

Am not sure what occurs this exactly. But most of the time passing a string value might not be enclosed with quotes. Put debugger on OnBeforeRequest and check. If the issue is with the quotation adding like below will resolve it. 


if possible, could you share the OML so we can help to resolve it quickly

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.