Remove queryparam after assign message to payload

pxzxz1
New Member

Hello Apigeeks

<AssignMessage async="false" continueOnError="false" enabled="true" name="Payload">
    <DisplayName>Payload</DisplayName>
    <Set>
        <Payload contentType="application/json">
            {"bookid":"{request.queryparam.bookid}"}
        </Payload>
    </Set>
    <Remove>
        <QueryParams>
            <QueryParam name="bookid"/>
        </QueryParams>
    </Remove>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Above, I set json payload from the queryparam and removed them from queryparam. Next, I print proxy request with javascript policy.

var req_request_uri = context.getVariable('proxy.url');
print(req_request_uri);

Result is not as expected. Supposingly, it only returns without the queryparam since I already removed them.

10075-screenshot.jpg

0 4 743
4 REPLIES 4

In my experience, the AssignMessage works as intended. A few points of feedback though.

  1. If you are assigning a payload, then you need to also insure the verb is PUT or POST (or something appropriate). You may have already done that; I don't see it in the config you have shown.
  2. The attachment point is important. I would suggest attaching that in the target request flow.

Here is my working example.

pxzxz1-remove-query-param-apiproxy.zip

I think the reason you are seeing different result sis possibly because of the attachment point you used for the AssignMessage policy. Consult my example to see what works.

Hello @dino-at-google

Thank you for the demo. Unfortunately, it does not work. I do not understand

  • AM-CleanResponseHeaders - why is it at proxy preflow response?
  • AM-Payload - Why is it at target request flow?

For this proxy, it is a no target endpoint. I accept queryparam such that it is ?bookid=10. I will use assign message policy to take the queryparam, set it as a request payload i.e. {"books": {"bookid": "10"}}

After that, remove the queryparam from the proxy path and execute service callout to the target endpoint with a request payload.

Unfortunately, it does not work.

I'm really sorry about that. Also, I have no idea how to help you further because I cannot diagnose a problem with a report like "it does not work".

If you do not understand why policies are attached at specific points, please consult the documentation regarding preflow, postflow, and other attachment points.

I hope after you read a bit more, you'll be able to use my example as a starting point to accomplish what you want. Good luck!

Not applicable

@Patricia,

Actually there is a misunderstanding. The assign-message policy is removing the query parameter from the request. If you see the request flow further the query param is not available in the flow.

when you are printing the proxy.url this will be showing because the proxy url variable is set at the beginning when the request reaches the message processor and that is the same in the flow. The assign message policy is not doing any change in proxy url. The policy is removing the queryparam from the request flow directly. This is working in my case.