Sending Payload as "x-www-form-urlencoded" type using Assign message Policy issue

Not applicable

Hi Everyone,

I am having an issue.

Trying to send data using assign message policy.

and the way we are sending the Payload is :

Type is : "x-www-form-urlencoded"

and key : value format.

key = "Key_name"

value = XML

I can't figure out how we should make a call for this from assign message.

Please see the snapshot ,i used postman to make a call which is working.

we need to make a call in same way from APigee.

TIA

0 6 12.7K
6 REPLIES 6

@gautam1 ,

Need more details regarding your query,

  • Are you trying to build a proxy for above-mentioned API ?
  • Are you trying to call above API as service callout inside Apigee Proxy ?
  • Why are you using Assign Message Policy ? Assign Message Policy is used to update / modify request / response payloads ?
  • If you want to make an API call to other service inside proxy, you will use service callout policy instead of Assign Message Policy ?

What exactly is the End Goal ? Need more details to better understand your issue.

Not applicable

Hi Sagar,

i have used Assign message on the Target endpoint flow.

Below is my Assign message policy and then Target Endpoint flow :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="am_setLogFireTargetParams">
    <DisplayName>am_setLogFireTargetParams</DisplayName>
    <Set>
        <Headers>
            <Header name="Authorization">Basic bGdmX3Jlc3Q6eHEyJDNjNg==</Header>
        </Headers>
        <Verb>POST</Verb>
        
        <Payload>{xml_data}</Payload>
    </Set>
    <AssignVariable>
        <Name>target.copy.pathsuffix</Name>
        <Value>false</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http"  type="request"/>
</AssignMessage>




//Target FLow


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="toLogFire">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>am_setLogFireTargetParams</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://uat.logfireapps.com/sears_uat/wms/api/init_stage_interface/.xml</URL>
    </HTTPTargetConnection>
</TargetEndpoint>

Not applicable

In Above Policies, I can send the XML data as a XML Payload.

That i want to change "x-www-form-urlencoded" (If you see the snapshot attached in the Question ,which is postman call ).

Thats exactly i want to make from Apigee.

If there is a better way than Assign Message policy , Please let me know.

Thanks for the Reply

Hi @gautam1 , in order to send messages as form-urlencoded data, you will need to send the data in the correct format using the AssignMessage policy.

Option 1:

Set the payload yourself with the right headers

<Set>     
    <Payload contentType="application/x-www-form-urlencoded">xml_data=%3C%3Fxml%20version%3D%221.0......</Payload>
</Set>

Note the key is xml_data (as in postman) and the value is the full urlencoded xml payload (as in postman)

Option 2:

1) Set the Content-Type header to application/x-www-form-urlencoded

<Set>     
    <Headers>      
        <Header name="Content-Type">application/x-www-form-urlencoded</Header>     
    </Headers> 
</Set>

2) Add the content body in the correct format (urlencoded string)

<Add>
    <FormParams>      
        <FormParam name="xml_data">%3C%3Fxml%20version%3D%221.0.....</FormParam>
    </FormParams>
</Add>

Again you could come up with your own innovative ways in which to create the urlencoded string within the proxy flow itself - like inside a JS policy and so on...

@gautam1

To access the form variables when content-type is x-www-form-urlencoded is to use request.formparam.{Variable_Name}. In your case, we can access the xml_data by using request.formparam.xml_data


You can use the following assignMessage policy.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<AssignMessage async="false" continueOnError="false" enabled="true" name="am_setLogFireTargetParams">

<DisplayName>am_setLogFireTargetParams</DisplayName>

<Set>

<Headers>

<Header name="Authorization">Basic bGdmX3Jlc3Q6eHEyJDNjNg==</Header>

<Header name="Authorization">Basic bGdmX3Jlc3Q6eHEyJDNjNg==</Header>

</Headers>

<Verb>POST</Verb>

</Set>

<Add>

<FormParams>

<FormParam name="xml_data">{request.formparam.xml_data}</FormParam>

</FormParams>

</Add>

<AssignVariable>

<Name>target.copy.pathsuffix</Name>

<Value>false</Value>

</AssignVariable>

<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<AssignTo createNew="false" transport="http" type="request"/>

</AssignMessage>




@gautam1

To access the form variables when content-type is x-www-form-urlencoded is to use request.formparam.{Variable_Name}. In your case, we can access the xml_data by using request.formparam.xml_data


You can use the following assignMessage policy.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<AssignMessage async="false" continueOnError="false" enabled="true" name="am_setLogFireTargetParams">

<DisplayName>am_setLogFireTargetParams</DisplayName>

<Set>

<Headers>

<Header name="Authorization">Basic bGdmX3Jlc3Q6eHEyJDNjNg==</Header>

<Header name="Authorization">Basic bGdmX3Jlc3Q6eHEyJDNjNg==</Header>

</Headers>

<Verb>POST</Verb>

</Set>

<Add>

<FormParams>

<FormParam name="xml_data">{request.formparam.xml_data}</FormParam>

</FormParams>

</Add>

<AssignVariable>

<Name>target.copy.pathsuffix</Name>

<Value>false</Value>

</AssignVariable>

<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<AssignTo createNew="false" transport="http" type="request"/>

</AssignMessage>