passing xml in queryparam in AssignMessage - apigeex

We are trying to set two QueryParams one with standard value of a string & another with a XML value as below but looks like the XML value is not being set as query parameter in the request to target. Could you please let us know if we need to change anything to set xml content as a query parameter i n assign message policy?

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="AM-setPath">
<DisplayName>AM-setPath</DisplayName>
<AssignVariable>
<Name>target.copy.pathsuffix</Name>
<Value>false</Value>
</AssignVariable>
<AssignVariable>
<Name>target.url</Name>
<Value>http://prosdfsdf.asdf.com/ShippingAPI.dll</Value>
</AssignVariable>
<Set>
<QueryParams >
<QueryParam name="API">TrackV2</QueryParam>
<QuaryParam name="XML">
<TrackRequest USERID="{userid}">
<TrackID ID="{trackingnumber}"/>
</TrackRequest>
</QuaryParam>
</QueryParams>
<Verb>GET</Verb>
<Path/>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

0 6 283
6 REPLIES 6

It's strange to insert XML into a query param.  But, if you really want to do that, within AssignMessage, use a cdata section. 

<AssignMessage name='AM-1'>
  ...
  <Set>
    <QueryParams >
      <QueryParam name="API">TrackV2</QueryParam>
      <QueryParam name="XML"><![CDATA[
        <TrackRequest USERID="{userid}">
          <TrackID ID="{trackingnumber}"/>
        </TrackRequest>
      ]]>
      </QueryParam>
    </QueryParams>
    <Verb>GET</Verb>
  </Set>  
</AssignMessage>

It seems like you're using Apigee to somehow  connect to the USPS TrackV2 API .  And of course the USPS TrackV2 API accepts (requires) XML.  But you don't need to pass XML in queryparams. You can do that but it's a little unusual to do so.

You could pass userid and trackingnumber as query params, or maybe more appropriately as form params, and then on the other end, construct the required XML document for USPS within your receiving service.

But it's up to you.  

Hi Dino , we tried to send Query Params (GET)  or FormParams (POST) using above format & doesnt seem to work. Sending as Query Params it doesnt set the XML Query param even with CData sectiion but while sending as Form Params we see the XML form param being set but getting 400 Bad request from USPS.

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="AM-setPath-usps">
<DisplayName>AM-setPath-usps</DisplayName>
<AssignVariable>
<Name>target.copy.pathsuffix</Name>
<Value>false</Value>
</AssignVariable>
<AssignVariable>
<Name>target.url</Name>
<Value>http://production.shippingapis.com</Value>
</AssignVariable>
<Set>
<Path>ShippingAPI.dll</Path>
<Headers>
<Header name="Content-Type">application/x-www-form-urlencoded</Header>
</Headers>
<FormParams>
<FormParam name="API">TrackV2</FormParam>
<FormParam name="XML"><![CDATA[
<TrackRequest USERID="{uspsuserid}">
<TrackID ID="{trackingnumber}"/>
</TrackRequest>]]></FormParam>
</FormParams>
<!-- <QueryParams>
<QueryParam name="API">TrackV2</QueryParam>
<QuaryParam name="XML"><![CDATA[
<TrackRequest USERID="{uspsuserid}">
<TrackID ID="{trackingnumber}"/>
</TrackRequest>]]></QuaryParam>
</QueryParams> -->
<Verb>POST</Verb>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Sending as Query Params it doesnt set the XML Query param even with CData sectiion

 

<QueryParams>
  <!-- the following element is OK -->
  <QueryParam name="API">TrackV2</QueryParam>
  <!-- the following is mis-spelled -->
  <QuaryParam name="XML"><![CDATA[
    <TrackRequest USERID="{uspsuserid}">
    <TrackID ID="{trackingnumber}"/>
   </TrackRequest>]]></QuaryParam>
</QueryParams>

 

You have a typo. I should have mentioned this in my prior post. You have QuaryParam. It needs to be QueryParam.

that worked . Thanks Dino.

Also we trying to see if we can set the target (using Target servers for each of environment) instead of Assign Variable in AssignMessage Policy. Is there a way to use it from TargetServer even though the request is generated through AssignMessage Policy?

<AssignVariable>
<Name>target.url</Name>
<Value>http://production.shippingapis.com</Value>
</AssignVariable>

Once you've configured the Target Servers, you then change your target endpoint configuration to refer to the appropriate target server by using the load balancer configuration as per https://docs.apigee.com/api-platform/deploy/load-balancing-across-backend-servers#configuringatarget...

Your proxy will then use the appropriate target based on the environment its deployed to and the associated target server configuration for that environment.

Yes. and in case you were wondering, as far as I know, there’s no way to dynamically set the url when you are using the target server load balancing mechanism.