60
Views
8
Comments
Solved
Bad Request error when sending a request body with more than one root nodes
Application Type
Reactive
Service Studio Version
11.53.10 (Build 61105)

Hi guys,

We have the Elasticsearch platform working on our company and I'm using it's REST API to search for some documents.

This request body works fine when sent from POSTMAN:

But when I try to send it from my Outsystems app I keep getting this "Bad Request" error.

That's how I mapped the request to a structure:

It's worth noting that the request works fine if I remove the "Highlight" node.

Does anyone have a clue about the right way to map that king of request body (two root nodes) to an Outystems structure?

Thanks and best regards

2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

Hello André,

Hope you're doing well.

The first thing it comes to me when I check it is that objetivo inside highlight node is defined like this:

"objetivo": {}

Since you have those {}, it seems it should be a structure/node. Like fields and highlight. Seems a bit strange though, because it's defined as an empty structure. 

However, in your code, Objetivo attribute is defined as a simple data type (most likely a text).

As it seems, OutSystems is trying to bind a structure to a text, that's why you're getting a 400 Bad Request.


Why isn't it defined as a text like objetivo inside query node?

Something like this:

"objetivo": ""


Kind regards,

Rui Barradas

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

In addition, please increase the log level of the API, and check what is sent, and what is returned. Often the API returns an error message that can help you to determine what is wrong.

2023-10-06 11-44-47
Andre Valadares da Silva

Good advice Kilian, I'll increase the log level and see if it helps me to better understand the issue.

Thanks a lot

2023-10-06 11-44-47
Andre Valadares da Silva

Yes @Rui Barradas  I see your point.

The JSON request body sent via POSTMAN works that way and I admit I'm not sure why It's like that.

In this json structure:


I understan the "objetivo":"blah blah" under the "match" node contains a query term for the "objetivo" attribute in a elastic search document, and the "objetivo" under the "fields" node is there to tell elasticsearch It wants the queried terms to be highlighted when found in the same "objetivo" attribute.

But I really don't know how to represent that empty structure ("objetivo":{}) in Outsystems. It seems Outsystems allways expect a regular field under any structure field.

Anyways I'll follow Kilians suggestion and increase my log level to see if I can gather more info.


Thanks a lot for the help

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

I have seen REST APIs that, even when you'd normally pass a string, that a "null" value is denoted by an empty object. If that's the case here, you need a OnBeforeRequest to fix that. However, it's also possible that the "objetivo" of the highlight fields is actually an object with attributes, in which case you need to add those to the structures in OutSystems.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Checking e.g. here, it seems that there's indeed an object with further attributes.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

In addition, please increase the log level of the API, and check what is sent, and what is returned. Often the API returns an error message that can help you to determine what is wrong.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Checking e.g. here, it seems that there's indeed an object with further attributes.

2023-10-06 11-44-47
Andre Valadares da Silva
Solution

Problem solved guys!

I certainly wouldn't find the answer without @Rui Barradas and @Kilian Hekhuis tips.

The problem indeed was the type of "objetivo" under the "fields" node, that was being sent as a String (as pointed ou tby @Rui Barradas) . Since I coundn't figure it out how to map that empty structure that was accepted via POSTMAN, I tried adding attributes to this "objetivo" tag (as suggested by @Kilian Hekhuis) and that solved the problem.

Also, changing the log level was decisive since then I was able to check how the changes in the structures in Outsystems were being mapped to the final JSON request body.

Here is the expected JSON body:

and the Outsystems structure that worked:


Again, you were great, thanks! :)

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Glad we could help you solving your problem! Could you mark our posts that helped you as solution? Thanks!

2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

Hello André,

Hope you're doing well.

The first thing it comes to me when I check it is that objetivo inside highlight node is defined like this:

"objetivo": {}

Since you have those {}, it seems it should be a structure/node. Like fields and highlight. Seems a bit strange though, because it's defined as an empty structure. 

However, in your code, Objetivo attribute is defined as a simple data type (most likely a text).

As it seems, OutSystems is trying to bind a structure to a text, that's why you're getting a 400 Bad Request.


Why isn't it defined as a text like objetivo inside query node?

Something like this:

"objetivo": ""


Kind regards,

Rui Barradas

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

In addition, please increase the log level of the API, and check what is sent, and what is returned. Often the API returns an error message that can help you to determine what is wrong.

2023-10-06 11-44-47
Andre Valadares da Silva

Good advice Kilian, I'll increase the log level and see if it helps me to better understand the issue.

Thanks a lot

2023-10-06 11-44-47
Andre Valadares da Silva

Yes @Rui Barradas  I see your point.

The JSON request body sent via POSTMAN works that way and I admit I'm not sure why It's like that.

In this json structure:


I understan the "objetivo":"blah blah" under the "match" node contains a query term for the "objetivo" attribute in a elastic search document, and the "objetivo" under the "fields" node is there to tell elasticsearch It wants the queried terms to be highlighted when found in the same "objetivo" attribute.

But I really don't know how to represent that empty structure ("objetivo":{}) in Outsystems. It seems Outsystems allways expect a regular field under any structure field.

Anyways I'll follow Kilians suggestion and increase my log level to see if I can gather more info.


Thanks a lot for the help

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

I have seen REST APIs that, even when you'd normally pass a string, that a "null" value is denoted by an empty object. If that's the case here, you need a OnBeforeRequest to fix that. However, it's also possible that the "objetivo" of the highlight fields is actually an object with attributes, in which case you need to add those to the structures in OutSystems.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Checking e.g. here, it seems that there's indeed an object with further attributes.

2023-10-06 11-44-47
Andre Valadares da Silva
Solution

Problem solved guys!

I certainly wouldn't find the answer without @Rui Barradas and @Kilian Hekhuis tips.

The problem indeed was the type of "objetivo" under the "fields" node, that was being sent as a String (as pointed ou tby @Rui Barradas) . Since I coundn't figure it out how to map that empty structure that was accepted via POSTMAN, I tried adding attributes to this "objetivo" tag (as suggested by @Kilian Hekhuis) and that solved the problem.

Also, changing the log level was decisive since then I was able to check how the changes in the structures in Outsystems were being mapped to the final JSON request body.

Here is the expected JSON body:

and the Outsystems structure that worked:


Again, you were great, thanks! :)

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Glad we could help you solving your problem! Could you mark our posts that helped you as solution? Thanks!

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