AssignMessage policy clears original request

Hi,

I'm currently having an issue with a "AssignMessage" policy which clears my original request:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Prepare-generate-token">
    <DisplayName>Prepare generate token</DisplayName>
    <Add>
        <FormParams>
            <FormParam name="grant_type">client_credentials</FormParam>
            <FormParam name="client_id">{apigee_client_id}</FormParam>
        </FormParams>
    </Add>
    <AssignVariable>
        <Name>oauth_external_authorization_status</Name>
        <Value>true</Value>
        <Ref/>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

My original request contains a JSON payload. After execution of the step above, the request content body changes from the JSON to:

grant_type=client_credentials&client_id=<somevalue>

Is there a way to avoid that the body is replaced?

Thanks,

Koen

0 6 302
6 REPLIES 6

I haven't tested this, but you haven't specified the AssignTo parameter and I believe it defaults to using create new to true which would override your existing request object. Add assignto, and set createNew to false.

Hi dane knezic,

Thanks for your reply.

I've added the AssignTo tag, but this does not make any difference.

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

Kind regards,

Koen

Is your existing json body also form paramters? Otherwise you're mixing different types of content in your request body.

Otherwise can these be set as headers instead

I've created a sample API proxy where I take my request content and store it as the response content in the proxy request preflow.

print('REQUEST');
print(context.getVariable('request.content'));
context.setVariable('response.content', context.getVariable('request.content'));

As soon as I send a POST/GET with a JSON body (in postman), the response is the same JSON as the request: However, whenever I add an AssignMessage policy, containing the following ...

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-Sample-1">
    <DisplayName>Assign-Message-Sample-1</DisplayName>
    <AssignTo createNew="false" transport="http" type="request"/>
    <Add>
        <FormParams>
            <FormParam name="grant_type">client_credentials</FormParam>
        </FormParams>
    </Add>
</AssignMessage>

... my original request is gone and the response of the call becomes:

grant_type=client_credentials

Thanks in advance,

Koen

From the documentation:

When you add <FormParams>, Edge sets the request's Content-Type header to "application/x-www-form-urlencoded" before sending the message to the target service.

So content types are mixed ...

Couple things

1. The default behavior of AssignMEssage is to assign to the ambient message, accessible as context variable "message". This will be request in the request flow, and response in the response flow. So the behavior of your AM policy will vary depending on where you attach it. I didn't see a note on where you attached it; you need to consider that.

2. The <AssignTo createNew='false' type='request'/> doesn't do anything. The AssignTo element allows you to specify the name of the context variable to which you will be assigning. If you have an empty text value for AssignTo (<AssignTo.../>) then you haven't specified a target variable, and AssignMessage defaults to the "message" context variable.

Given this information can you re-try your proxy and see if you can get it to behave the way you want it to behave?

If that still does not lead to joy, please post the proxy (the simple repro case) here, as well as a curl command to cause the behavior that is vexing you.