I am consuming a REST API, and it returns an HTML type response, how can I convert it to a json object

Hi kaoutar,

Is this expected? If not, what is the expected result of the REST API you're consuming?
I would say that you are being redirected to a login page and the response is the login page? 

Cheers.

Eduardo Jauch wrote:

Hi kaoutar,

Is this expected? If not, what is the expected result of the REST API you're consuming?
I would say that you are being redirected to a login page and the response is the login page? 

Cheers.

no, the login is done correctly.
What happens is that, after doing the login, it goes to another screen, on this screen I have a TableRecord where the response(data) of a GET call is loaded.
The problem is: the result of the call (when I do the Test) is an html text, not a json object


Sorry, Let's start again from the beginning.

You said you're consuming a REST API. How are you calling the API method? Why the method is returning HTML and not JSON? Is this REST API you're consuming yours or is a Third Part REST API?

Cheers.

Hi Kaoutar,

The only "valid" reason that we see, in the "wild" that an HTML response is returned instead of a valid JSON response is when you call a wrong URL, and you get a response other than 200 (but one in the 400 range (like "404 resource not found") or 500 range (like "503 service unavailable")).

There is no way to "convert" HTML to JSON. HTML is not a valid REST method response, and should not be returned by any REST service when there's no error (i.e. the response is in the 200 range).

You have a different problem here, please investigate what is returned exactly (if you don't know how, see my post here).

maybe I have an error in the login. How can I login using api Rest post?

Ah... Now we're talking the same language again :D

It depends... How the REST API expects the authentication?
For example, if it expects basic authentication, you can setup it both in the code as well as in the Service Center:
https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/REST/Consume_REST_APIs/Consume_a_REST_API
and
https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/REST/Consume_REST_APIs/Configure_a_Consumed_REST_API_at_Runtime
If it needs something different, you may need to use the REST OnBeforeRequest (for example), to manipulate the REST request to add things for authentication.

It will depend on the REST you are calling.


Eduardo Jauch wrote:

Ah... Now we're talking the same language again :D

It depends... How the REST API expects the authentication?
For example, if it expects basic authentication, you can setup it both in the code as well as in the Service Center:
https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/REST/Consume_REST_APIs/Consume_a_REST_API
and
https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/REST/Consume_REST_APIs/Configure_a_Consumed_REST_API_at_Runtime
If it needs something different, you may need to use the REST OnBeforeRequest (for example), to manipulate the REST request to add things for authentication.

It will depend on the REST you are calling.


I'll try again, thanks for your help :)


Kilian Hekhuis wrote:

Hi Kaoutar,

The only "valid" reason that we see, in the "wild" that an HTML response is returned instead of a valid JSON response is when you call a wrong URL, and you get a response other than 200 (but one in the 400 range (like "404 resource not found") or 500 range (like "503 service unavailable")).

There is no way to "convert" HTML to JSON. HTML is not a valid REST method response, and should not be returned by any REST service when there's no error (i.e. the response is in the 200 range).

You have a different problem here, please investigate what is returned exactly (if you don't know how, see my post here).


thank you :)

 HEEEEEEEEEEEEELP

I make a REST request (post) , using postman, the answer is as follows:


I make the same request by consuming a REST api (post) from outsystem and it returns the following:
can someone help me to know where the problem comes from and how to solve this plzzzz

Hi Kaoutar,

I would assume that's because in Postman, you have entered credentials, and in OutSystems, you have not - given that there's no userInfo. What's strange though is that both seem to reply with a 200 OK response.

I have entered the same credentials in both, I made the same request, but the result is different

Still, what is sent is different, or you wouldn't get a different response :).

Kilian Hekhuis wrote:

Hi Kaoutar,

I would assume that's because in Postman, you have entered credentials, and in OutSystems, you have not - given that there's no userInfo. What's strange though is that both seem to reply with a 200 OK response.

This is probably because they are not using the returning code "semantically". Login failing or not, they seem to be returning 200.

kaoutar elkarkri wrote:

I have entered the same credentials in both, I made the same request, but the result is different

Did you check if you are using the same method as in Postman (POST, GET, etc)?
How are you passing the credentials in Postman and in OutSystems (Basic Authentication)?
Are you really sure you are passing the same credentials in both sides? Like, no typos, etc?

Cheers.

request Postman:





Request Outsystems:


in case of putting the wrong credentials, it returns an error, not "200 ok"

That's not the right error code either :). Anyway, the "test" REST is difficult to debug. Is advise you to makes a testing screen, and set the REST logging to full, to see what is actually sent and received.