Rest API call using xml data

Rest API call using xml data

  
Hi 

I was wondering how would I get data from an xml to my outsystems entities.

For example, I have a Rest Api service link to get customers.

I paste that link in the Rest console to get the data.

I recieve the list of customers in xml format.

Now when I go into Service studio,

I consume a new Rest Api

I paste the url to get the customers and the xml it returned in the rest console.

When i click ok, it creates the action for me 

But in my data tab, in the structures folder, the structure entity is suppose to be created with the attributes on the xml. 

In my case this structure does not show.

How can I resolve this?

Kind Regards

Tyrone
Hi Tyrone,

Since you're integrating with a REST API that will return an XML response, the Response Format needs to be configured as Plain Text.

In this case, you will not get an automatically defined Structure like you get when you use a JSON approach, so you will need to convert the returned Text to the correct Record/Record List. To do this you can use some functions that are part of the Xml component that should already be part of the System Components installed with your Platform or you can have a look at the XML Records component available on Forge (http://www.outsystems.com/forge/component/153/xml-records/).

If you have the option to use a JSON version of the Web Service, the Platform would be able to automatically infer the Structure that would be returned.

Best regards,

Tito Azevedo
Hi Tito 

Thanks for the feedback

I converted my xml response to json

Then the structures are created for me.

But when I run this

I get this error
Failed to parse response of the method 'GetCUSTOMER' of the 'GETCUSTOMERLIST' Web Reference:
Parsing '': Unexpected character encountered while parsing value: <. Path '', line 0, position 0.

What does this mean?

Kind Regards

Hi Tyrone,

How did you convert the XML to JSON? Do you have a JSON version of the WebService? 

If the WebService response is still XML, converting it to JSON won't be enough to get it to work.

Best regards,

Tito Azevedo
Hi Tito

You can convert it with a program online

This is the link for interest http://www.freeformatter.com/xml-to-json-converter.html#ad-output

It lets you paste your xml and converts it into a json payload

What other options can I take to get the XML data using consume rest api?

Kind Regards