The use of "question mark" in Proxy Endpoint and Target Endpoint

Not applicable

I have two questions regarding the use of "question mark" in endpoints, and hope you can kindly help me out.

1. My proxy endpoint

/v1/product/books?parameters

target endpoint to be

http//mysite.com/v1/product/parameters (so in this case, no question mark included)

I then use Assign Message to pass on the parameters:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="SetTargetURL">
    <DisplayName>SetTargetURL</DisplayName>
    <AssignVariable>
        <Name>target.url</Name>
        <Value>http://mysite.com/v1/product/{request.querystring}</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage><br />

I though this would be ok to pass the parameter to the target endpoint, as

{request.querystring} = "The portion of the HTTP request path after the question mark ( ? )"

(according to https://docs.apigee.com/api-platform/reference/variables-reference)

but in the Edge Trace log and the curl commandline, the target endpoint still contains the question mark, which I wish to drop.

Is there a way to remove the question mark for the target endpoint? Please advise.

2 - For the use of API Key in proxy endpoint, if I append ?apiid=xxxxxxxxxx in the parameter string it works as expected. But when I am testing the Specs with the proxy, the api key is automatically added in this way staring with the usual 'and' sign say &key=xxxxxxxxxx in the curl commandline, not using the "?" any more. How to reconcile this or keep this consistent?

Thanks a lot.

0 9 700
9 REPLIES 9

Hi Tim, when we use API Key or OAuth policies we often send the key/token in query/header parameters. The validation occurs on ProxyEndpoint & hence after the respective policy we can use an Assign Message Policy to remove the parameter before hitting the Target.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>Assign Message-1</DisplayName>


    <Remove>
        <Headers>
            <Header name="Authorization"/>
        </Headers>
        <QueryParams>
            <QueryParam name="apikey"/>
        </QueryParams>
        <FormParams>
            <FormParam name="f1"/>
        </FormParams>
        <Payload/>
    </Remove>
    
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

For your first question, we can either use a Javascript policy or Assign message policy to to set the pathsuffix to false,

context.setVariable("target.copy.pathsuffix", false)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="AssignMessage.DisablePathCopy">
    <Remove>
        <QueryParams>
            <QueryParam name="q1"/>
            <QueryParam name="q2"/>
        </QueryParams>
        <Payload/>
    </Remove>

    <AssignVariable>
        <Name>target.copy.pathsuffix</Name>
        <Value>false</Value>
    </AssignVariable>
</AssignMessage>

Either of these policies should be added in the TargetEndpoint "preflow" and it will not append pathsuffixs on TargetURL.

hr-api-rev21-2018-05-28.zip

Thanks, Siddharth.

1 - For the first question, this would only remove the proxy.pathsuffix part (i.e. /books in my case), and the target endpoint is still with the question mark, i.e. http//mysite.com/v1/product/?parameters, as seen in the curl commandline in Trace.

Are you able to make a simple proxy zip file to illustrate that the "?" from the proxy endpoint will not be passed to the target endpoint? Thanks in advance.

2 - For the second point, thanks for the explanation.

I think target.copy.pathsuffix should also remove queryparams. Maybe I am confused, I will give it a try and update here. Till then you can use Assign Message Policy to remove query param same as apikey example.

-edit-

target.copy.pathsuffix only removes paths for queryarams I am using Assign message policy. I have updated my above answer and added a sample proxy zip. Please have a look

What I have done so far:

a - put the following Assign Message at Target Endpoint | PostFlow

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="SetTargetURL">
    <DisplayName>SetTargetURL</DisplayName>
    <AssignVariable>
        <Name>target.url</Name>
        <Value>http://mysite.com/v1/product/{request.querystring}</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage><br /><br>

b - Then go check the Trace Tab and click the transaction map icon "Request sent to target server"

From there, the Get message seems right, display http//mysite.com/v1/product/parameters as expected, but in the next "Show Curl' message, the curl commandline still shows http//mysite.com/v1/product/?parameters. I guess here where my trouble lies.


As you dont want to filter payhsuffix you can ignore/remove target.copy.pathsuffix.

b - Then go check the Trace Tab and click the transaction map icon "Request sent to target server"
From there, the Get message seems right, display http//mysite.com/v1/product/parameters as expected, but in the next "Show Curl' message, the curl commandline still shows http//mysite.com/v1/product/?parameters. I guess here where my trouble lies. 

This happens when you add Assign Message Policy on the Response flow?

Add the policy on the Request flow.

Thanks. Now it seems you have removed the parameters string altogether. In the curl commandline, the target address becomes http//mysite.com/v1/product/, no parameters attached.The {request.querystring} becomes blank. I still need the parameter string to be passed on.

PFA Proxy Bundle tim-proxy-rev1-2018-05-28.zip

Deploy the proxy and try with queryparam q1, values can be Siddharth or Thomas and we can see that the value we pass is appended to the target url as expected.

http://org-env.apigee.net/tim-proxy?q1=Siddharth
http://org-env.apigee.net/tim-proxy?q1=Thomas

The link you have shared is broken and I am not able to access it.

Thanks you Siddharth for more information. I have now figured this out as well. As soon as I see the difference between the Get message and the curl commandline in Trace, I should move the assign message SetTargetURL to the request side, instead of keeping it in the response side. Thanks again.

Hello Tim, Does the below piece of code substitute the value of {request.querystring} in the path? When <Value> is used in AssignVariable, it generates a static output, meaning target URL generated would be as 'http://mysite.com/v1/product/{request.querystring}'

<AssignVariable><Name>target.url</Name><Value>http://mysite.com/v1/product/{request.querystring}</Value></AssignVariable>