none
xml from get method of API RRS feed

  • Question

  • I have a very simple scenario I am trying I have API Get method which returns me JSON payload. I want it converted to XML.

    How can I do that? I know some function called @xml but not sure how to use?  I can think few option like writing function but I am sure it has easier way, can somebody explain me?

    Thursday, September 7, 2017 5:06 PM

Answers

  • Hi ,

    Then just reverse the expression :) .

    @xml(json(body('GETAPICalls')))


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply

    • Marked as answer by dnyanbhar Friday, September 8, 2017 7:54 PM
    Friday, September 8, 2017 4:02 AM
  • Hi,

    I think it should not be a problem if you are calling the api using a swagger. The response will contain the headers, the body and status code, so just use the body from the http swagger and convert it to xml.

    You need to note that the @xml() function can convert only one property in json message, if there are multiple properties in the response you will get an error.


    Mandar Dharmadhikari

    • Marked as answer by dnyanbhar Friday, September 8, 2017 7:56 PM
    Friday, September 8, 2017 4:20 AM
  • As Abhishek Said you can just simply use the Http Connector if you are using Swagger

    Sujith


    Friday, September 8, 2017 6:35 AM
  • Thanks, guys, I was able to get what I need. I made following changes.

    1)Used HTTP in place of HTTP + swagger

    2)Concat root node to JSON and use the expression for XML as suggested.

    Used following expression in design view xml(json(concat('{"rootNode":',string(concat(string(triggerBody()),'}')))))

    • Marked as answer by dnyanbhar Friday, September 8, 2017 7:54 PM
    Friday, September 8, 2017 7:54 PM

All replies

  • you can do it from the Expression editor itself like below

    in the similar way you can do it for your API Method as well.

    if you want to do it in the code view it will be like below

    if you are getting json from a Trigger then you will be using like below

    @xml(triggerBody())

    in your case its an Get Api method, so you will be doing like

    @xml(GetApi())



    Sujith


    Thursday, September 7, 2017 7:30 PM
  • I have Get method, can I use Request response for Get?
    Thursday, September 7, 2017 8:40 PM
  • if you already have a get method you dint need to use request 

    you would just call that API method and get your response. in the response you will use the XML function to convert it.

    let me know if i understood anything wrong about your issue


    Sujith

    Friday, September 8, 2017 12:49 AM
  • Hi ,

    So what is the problem you are facing ?

    When you do a get operation ,you will be getting xml as response from the web api and then you need to translate xml to JSON using @json(xml(body('GETAPICalls')))

    If your logic apps is exposed as request response service then use the above expression in the response action .That will give you JSON string as output 


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply

    Friday, September 8, 2017 2:13 AM
  • my requirement is the reverse, I have web API which I called using HTTP swagger I am getting JSON now I want to convert it into XML
    Friday, September 8, 2017 3:59 AM
  • Hi ,

    Then just reverse the expression :) .

    @xml(json(body('GETAPICalls')))


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply

    • Marked as answer by dnyanbhar Friday, September 8, 2017 7:54 PM
    Friday, September 8, 2017 4:02 AM
  • how can I call it? I am using HTTP swagger, is any other way to call it?
    Friday, September 8, 2017 4:02 AM
  • Hi,

    I think it should not be a problem if you are calling the api using a swagger. The response will contain the headers, the body and status code, so just use the body from the http swagger and convert it to xml.

    You need to note that the @xml() function can convert only one property in json message, if there are multiple properties in the response you will get an error.


    Mandar Dharmadhikari

    • Marked as answer by dnyanbhar Friday, September 8, 2017 7:56 PM
    Friday, September 8, 2017 4:20 AM
  • Hi,

    I think you need to do it and let us know if you face any issue?

    Swagger is nothing but a exposed data contract for the web api  .

    You will be using the same HTTP connector and select the Operation type as GET and in the uri properties pass your web api controller method action . (you can find the uri when you are testing the service through swagger )


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply

    Friday, September 8, 2017 4:27 AM
  • As Abhishek Said you can just simply use the Http Connector if you are using Swagger

    Sujith


    Friday, September 8, 2017 6:35 AM
  • I used HTTP as said I can see JSON in body of it when I run just that connector.

    Now I want to convert that to xml, so what action I should use and where I should use above expression. In http 

    I mentioned Method as Get

    URI as my uri

    Friday, September 8, 2017 5:19 PM
  • what is your json body??

    just pass it to the xml() expression. but as i suspect if the json has multiple properties, you will get runtime error 


    Mandar Dharmadhikari

    Friday, September 8, 2017 5:21 PM
  • you mean in Body of HTTP I should use XML()? Right now I have multiple properties I am fine to take one for now and later change the structure. But I should get that error

    Friday, September 8, 2017 5:33 PM
  • say your http body is json message then you can use something on below lines

    @xml(body('Get_forecast_for_today'))

    here Get_forecast_for_today is the api and I converting the body returned by this GET into xml using above code. It should be used in the code view of logic app

    If you want to do it using the designer,

    Go For set dynamic content> then go to expressions tab> Select xml expression and put  body(apiname)in the brackets 

    Also remember to set the content-type to application/xml on the response


    Mandar Dharmadhikari

    Friday, September 8, 2017 5:46 PM
  • Thanks, guys, I was able to get what I need. I made following changes.

    1)Used HTTP in place of HTTP + swagger

    2)Concat root node to JSON and use the expression for XML as suggested.

    Used following expression in design view xml(json(concat('{"rootNode":',string(concat(string(triggerBody()),'}')))))

    • Marked as answer by dnyanbhar Friday, September 8, 2017 7:54 PM
    Friday, September 8, 2017 7:54 PM