how to forward the query string

Not applicable

Hi Team,

How to forward the query string in Apigee.

example: we have application and it will make the api call to URL/connect. The application will create a query string like below.

URL + event.path + "?projectId=" + event.args['projectId']

We have configured the request method as below and it's not appending the query params when we made the request to URL/connect via application.

<Flow name="connect"> <Description>importer api</Description> <Request> <Step> <Name>Quota-2</Name> </Step> </Request> <Response/> <Condition>(proxy.pathsuffix MatchesPath "/connect") and (request.verb = "POST")</Condition> </Flow>

Regards,

Sarguru

1 5 5,658
5 REPLIES 5

Dear @sargurunathan,

If you are looking for a way to retrieve the query parameters in the API proxy from your application's query string, then you can use the built-in variable message.querystring or request.querystring.

In your case, these variables will have the value of => projectId=" + event.args['projectId'].

If you are looking to retrieve the entire path (including the query parameters) after the URL, then you can use the built-in variable message.uri or request.uri.

In your case, these variables will have the value of => event.path + projectId=" + event.args['projectId'].

You can read more details about built-in variables in Apigee here.

Having said that, if you were looking for something else, please do provide some more details on what exactly you are looking for. I will be glad to help you.

Thanks,

Amar

Hi Amar,

Thanks for the update. can you give me the example message policy to forward request URI.

Regards,

Sargurunathan

Dear @sargurunathan,

Looks like you want to use the query string in the target URL. If that's right, then you can use the AssignMessage policy as shown in the below sample policy:

<AssignMessage async="false" continueOnError="false" enabled="true" name="SetTargetURL">
  <DisplayName>SetTargetURL</DisplayName>
  <AssignVariable>
    <Name>target.url</Name>
    <Value>http://{yourtargethostname}?{request.querystring}</Value>
  </AssignVariable>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Regards,

Amar

You shouldn't have to manipulate anything for query parameters to be passed through the proxy. Can you provide more details as to what you are seeing? What is the request the caller is making and what is the request the target is seeing?

I am using two steps for setting up target.url like

<Step>

<Name>am-set-target-params</Name>

</Step>

<AssignVariable> <Name>target.url</Name> <Template>{target_host_basepath}{proxy.pathsuffix}</Template> </AssignVariable>

<Step> <Name>am-set-target-query-params</Name>

<Condition>request.querystring != null</Condition>

</Step>

<AssignVariable> <Name>target.url</Name> <Template>{target.url}?{request.querystring}</Template> </AssignVariable>

al

Along with HTTPTargetConnection-->URL-->https://will.be.replaced