{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • General /
avatar image
0
Question by Ken Dunnington · Apr 23, 2020 at 10:41 PM · 48 Views variableassignmessagejsontoxml

Using variables to craft XML request from JSON using AssignMessage payload

I'm building an API that talks to a SOAP backend. The proxy accepts a JSON payload, and I need to convert that to XML. The issue I'm having is that the payload I'm getting is complex, so I can't simply extract a few variables from it and then build the XML payload. What I'd like to do is extract the large chunks of data from the JSON, use JSONtoXML to convert that to XML format, then extract what I need, and inject it into a custom XML payload using AssignMessage.

When I tried this, though, I couldn't figure out how to inject a block of XML into the message. For example, assume I get a payload like this:

// The actual data is much, much larger, and includes several levels of nesting
{
"foo": "bar", "baz": 12345
}

I can run this through a JSONtoXML policy and get this:

<?xml version="1.0" encoding="UTF-8"?><Root>  <foo>bar</foo>  <baz>12345</baz></Root>

What I want to do next, is be able to extract those two XML nodes, `foo` and `bar`, and use them in an AssignMessage like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Create-Auto-Request">
    <DisplayName>Create Auto Request</DisplayName>
    <Properties/>
    <Set>
        <Payload contentType="text/xml">
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://some.net/namespace">
                <soapenv:Header/>
                <soapenv:Body>
                    <v1:someService xmlns:v10="http://some.net/othernamespace">
                        <request>
                            <ServiceInformation>
                                <Environment>{request.header.environment}</Environment>
                            </ServiceInformation>
                            {foo}
			    {bar}
                            <SomeOtherInformation/>
                        </request>
                    </v1:someService>
                </soapenv:Body>
            </soapenv:Envelope>
        </Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

When I try this, I get blanks. Is it even possible to use message templates in this context? Should I convert my JSON to XML strings using JavaScript?

Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

1 Answer

  • Sort: 
avatar image
1
Best Answer

Answer by dane knezic   · Apr 24, 2020 at 01:49 AM

I believe for your approach to work, you would need to use Extract Variables to extract your individual json variables (ie so you'll have the actual values for foo and baz. Then you'll need to specify the xml structure in your assign message eg

<ServiceInformation>
   <foo>{fooValue}</foo>
   <baz>{bazValue}</baz>
</SomeOtherInformation>

For what you're trying to do, I would instead consider looking at using the XSLT policy after you do the initial JSON -> XML conversion. It looks like you want to do more specific mapping of an XML structure, where as the assign message with the variables is better suited for building strings

Comment
Add comment Show 2 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ken Dunnington · Apr 24, 2020 at 01:03 PM 0
Link

Thanks! I'll give those approaches a try. I was hoping to avoid the XSLT route, but that may be the best option available.

avatar image Dino-at-Google ♦♦ Ken Dunnington   · Apr 24, 2020 at 02:01 PM 1
Link

I agree; for generating dynamic SOAP messages, XSLT is the best option. (sorry. But your fate was sealed when you used SOAP)

Follow this Question

Answers Answers and Comments

52 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to update a nodeset variable? 1 Answer

List full array headers of the same name 1 Answer

JSON to XML conversion- issue with root element 0 Answers

How to access variable present in node.js file in java script file 1 Answer

Assign a value read from KVM to a header name 1 Answer

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges