Azure Logic Apps部署为REST API后,调用API并XML转JSON的实现方法
How to Call External REST API for XML Data & Convert to JSON in a REST-Triggered Azure Logic App
Hey there! Since you're coming from WSO2 ESB and just getting started with Azure Logic Apps, let me walk you through exactly how to set up this workflow step by step—it’s more straightforward than you might think.
Step 1: Set Up Your REST-Triggered Logic App
- First, create a new Consumption or Standard Logic App (Consumption is perfect for serverless, pay-as-you-go use cases).
- For the trigger, search for "When a HTTP request is received"—this acts as your Logic App’s REST API entry point.
- You can optionally define a request JSON schema here to validate incoming calls, but it’s not required for this scenario. Save the trigger, and you’ll get a unique HTTP endpoint URL to call your Logic App later.
Step 2: Call the External REST API for XML Data
- Click + New step to add an action, then search for and select the "HTTP" action.
- Configure the HTTP action to match the external API’s requirements:
- Pick the correct Method (GET, POST, etc.).
- Paste the external API’s URI.
- Add any necessary headers (like
Accept: application/xmlif the API defaults to XML responses) or query parameters.
- Run a test trigger to confirm this action pulls in the XML payload successfully—you can check the action’s output to verify the XML data is coming through.
Step 3: Convert XML to JSON
- Now, let’s turn that XML into JSON. Add another new step, search for "Parse XML" and select it.
- In the Content field, select the body output from your HTTP action (it’ll look like
body('HTTP')in the dynamic content picker). - For the Schema, you have two easy options:
- Use a sample XML payload: Click Use sample payload to generate schema, paste your XML sample, and Logic Apps will auto-create the schema for you (this is the quickest way!).
- Manually define the schema if you don’t have a sample, but auto-generating is way less error-prone.
- The Parse XML action already converts XML into a structured JSON-like object that you can use in subsequent steps. If you need a pure JSON string, use the
json()expression to explicitly convert it—for example, in a Compose action:json(string(body('Parse_XML')))
Step 4: Return the JSON Response (Optional)
- If you want to send the JSON back as the response to the original REST call to your Logic App, add a "Response" action at the end.
- Configure it:
- Set a Status code (like 200 OK).
- In the Body field, select the output from your Parse XML or Compose action.
- Add a header
Content-Type: application/jsonto let the caller know the response is JSON.
Quick Tips for Your WSO2 to Logic Apps Transition
- Think of Logic App actions like WSO2 ESB mediators—each handles a specific task (API calls, data transformation, etc.).
- The Parse XML action replaces the need for Payload Factory or XSLT mediators for basic XML-to-JSON conversions, and it’s far more streamlined for most use cases.
- Test each step individually using Logic Apps’ built-in test feature to catch issues early (like wrong API endpoints or missing auth headers).
内容的提问来源于stack exchange,提问作者VIKRAM
相关产品推荐
相关产品推荐

