Adding Headers and Body params in Assign Message Policy to create Xml payload

Not applicable

Hi ,

When adding Request Body and Header parameters in Assign Message Policy to create Xml Paylaod, it will accept only thos parameters which I added first - For example, when added 5 Header parameter and then six Request Body or Form param , it will accept only Headers fields but not the Body parameters.
Any clue, where is the problem?

1 11 7,946
11 REPLIES 11

Can you show the policy configuration for your AssignMessage policy, please?

Hi Rajeev - Can you share your assign-message policy and your desired output?

Not applicable

This is Assign Message Policy , I am using

-------------------------------------------------

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-BuildXmlProbeReqPayload">
<DisplayName>AM-BuildXmlProbeReqPayload</DisplayName>
<Properties/>
<Set>
<Headers>
<!-- The list of below Headers must set by client (Postman/Trace tool) when calling Probe Proxy API. -->

<Header name="Accept">{request.header.Accept}</Header>
<Header name="X-VGT-Labels">{request.header.X-VGT-Labels}</Header>
<Header name="GIMSenderId">{request.header.GIMSenderId}</Header>
<Header name="X-VGT-UserId">{request.header.X-VGT-UserId}</Header>
<Header name="Content-Type">{request.header.Content-Type}</Header>



<!-- Access token retrieve from the Probe authorization API using SC-ProbeToken & EV-RetrieveProbeToken-->

<Header name="X-VGT-UserToken">{access_token}</Header>

</Headers>

<Verb>POST</Verb>
<!-- Retrieving parameter from the Request body & creating the request payload-->

<Payload>
<!-- All the below fields pass as Request Body parameter in Postman or similar some tool when calling this Proxy API.
limit is mandatory parameter -->
<ProbeSearch>
<limit>{request.formparam.body_param_1}</limit>
<vin>{request.formparam.body_param_2}</vin>
<startTime>{request.formparam.body_param_3}</startTime>
<stopTime>{request.formparam.body_param_4}</stopTime>
<type>{request.formparam.body_param_5}</type>
<serviceId>{request.formparam.body_param_6}</serviceId>
<sourceId>{request.formparam.body_param_7}</sourceId>
<skip>{request.formparam.skip}</skip>
</ProbeSearch>

</Payload>

</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Thanks! I have created a simple proxy and added this policy. It seems to be adding both Headers & payload - See below :

Client Request -

4639-apigee-rest-client-1.png

4640-apigee-rest-client-2.png

When I trace, I see the following after this policy is executed -

4641-apigee-rest-client-3.png

Am I missing something?

Exactly what I am expecting, but my Assign Message Policy is either hold Header param or Body param but not the both. Can you please send your Assign Message Policy or review my policy above on the same page?
Thanks

I just hard-coded a few values otherwise it's exactly the same config you have -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-BuildXmlProbeReqPayload">
    <DisplayName>AM-BuildXmlProbeReqPayload</DisplayName>
    <Properties/>
    <Set>
        <Headers>
            <!-- The list of below Headers must set by client (Postman/Trace tool) when calling Probe Proxy API. -->
            <Header name="Accept">{request.header.Accept}</Header>
            <Header name="X-VGT-Labels">{request.header.X-VGT-Labels}</Header>
            <Header name="GIMSenderId">{request.header.GIMSenderId}</Header>
            <Header name="X-VGT-UserId">{request.header.X-VGT-UserId}</Header>
            <Header name="Content-Type">{request.header.Content-Type}</Header>
            <!-- Access token retrieve from the Probe authorization API using SC-ProbeToken & EV-RetrieveProbeToken-->
            <Header name="X-VGT-UserToken">accesstoken</Header>
        </Headers>
        <Verb>POST</Verb>
        <!-- Retrieving parameter from the Request body & creating the request payload-->
        <Payload>
            <!-- All the below fields pass as Request Body parameter in Postman or similar some tool when calling this Proxy API.
limit is mandatory parameter -->
            <ProbeSearch>
                <limit>{request.formparam.body_param_1}</limit>
                <vin>{request.formparam.body_param_2}</vin>
                <startTime>{request.formparam.body_param_3}</startTime>
                <stopTime>{request.formparam.body_param_4}</stopTime>
                <type>{request.formparam.body_param_5}</type>
                <serviceId>{request.formparam.body_param_6}</serviceId>
                <sourceId>{request.formparam.body_param_7}</sourceId>
                <skip>{request.formparam.skip}</skip>
            </ProbeSearch>
        </Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Thanks sudheendra.
Any clue, why it is not working on my machine?

nothing off-hand... but can you check your request content-type. I'm doing a POST with content-type as -

application/x-www-form-urlencoded

Hi Sudheendra,

Thanks for your support but I have to use - Content-Type = application/xml. My target back end service expecting - Content-Type = application?xml

and I have to set this in the Request Header with other parameters in the Request Body.

I am creating Xml Request Payload with Header and Body parameters supplied by calling client (Postman etc.)

Is it not work with -

Content-Type = application?xml ?

Hi @RejeevChaturvedi ,

Please clarify if you want to accept data from API consumer in the application/xml or if you want to accept it into form-data and then convert it into xml payload.

There are two things -

1. If you want to keep both API consumer and backend system formats same then you use application/xml as content type when you hit API-> pass the xml payload in the format you have mentioned in assign message and get rid of assignmessage policy. This will make your proxy a pass-through from transformation perspective. Of course you are free to add other features of API management in the proxy.

2. If you want to accept form data from API consumer(postman/API console) then you can use your assignmessage policy to extract the data from request, create a xml payload the way backend expects and change the header value to application/xml before sending this to backend system. In this case you have to change only one line in your assignmessage policy(the one you have given above) -

<Header name="Content-Type">application/xml</Header>

I hope this will help.

Thanks,

Santosh