Need to modify response from target server before sending to consumer based on developer app name

Hi,

I have to modify/ the response coming from my target server before sending the response to proxy consumer.

This response modification is specific to few consumers of our API proxy. Means, I need to modify the response only for few consumers based on their developer app name.

I found that, we can edit the response coming from Target server in the proxy flow with the help of Assign Message policy. Can we do this with SET option from Assign Message policy ? Also, How to add conditional based response setting in AssignMessage policy ? can we get and use the Developer app names based on access_token in the request header ? which is the best place to configure my list of developer app names for which I need to modify the response in my proxy response flow ? What do you suggest here ? KVM or as API product attributes ? Thanks.

Solved Solved
0 8 2,738
1 ACCEPTED SOLUTION

sidd-harth
Participant V

Yes, you can add it on the Proxyendpoint response flow. Generally speaking, the Proxyendpoint is faced by the App and the Targetendpoint connects with the backend, so I tend to keep all backend related response/modifications on the Targetendpoint side and transformations on the Proxyendpoint side. But you can do it either way on the response side, not an issue.

Yes, you can use comma separated values in product attributes.

Follow below doc to compare the values using JS,

https://community.apigee.com/questions/1977/comparing-a-variable-against-a-custom-attribute-va.html

View solution in original post

8 REPLIES 8

sidd-harth
Participant V

When you verify the access token, the developer.app.name flow variable is populated by the oauth policy.

I would recommend you to modify the response on the Targetendpoint side and manage any transformations on the ProxyEndpoint.

Yes, you can use Assign Message or Javascript to form a new payload/response. Use the developer.app.name flow variable as Conditions.

Regarding storing the developer app names, it depends on the number of apps you want to store, because the API Product attributes have a limit.

Using a KVM is not bad either, I am thinking of using a single Key with all the developer app names as comma separated, then in the proxy,you can Get the key value and compare using JavaScript logic.

Thanks @Siddharth Barahalikar for helping.

I am little confused with this "I would recommend you to modify the response on the Targetendpoint side and manage any transformations on the ProxyEndpoint."

I was thinking to add AssignMessage policy in Proxy response flow to alter the target server response before sending to our consumers.

With respect to Dev Apps, at the moment we have two consumer apps for which we need to alter the response. We can keep the Dev app names in KVM, but we can't see the list of dev app names if we need to in future.

Can we add a custom attribute in API product configuration to hold the list of Dev Apps by comma seperated ?


sidd-harth
Participant V

Yes, you can add it on the Proxyendpoint response flow. Generally speaking, the Proxyendpoint is faced by the App and the Targetendpoint connects with the backend, so I tend to keep all backend related response/modifications on the Targetendpoint side and transformations on the Proxyendpoint side. But you can do it either way on the response side, not an issue.

Yes, you can use comma separated values in product attributes.

Follow below doc to compare the values using JS,

https://community.apigee.com/questions/1977/comparing-a-variable-against-a-custom-attribute-va.html

Thanks @Siddharth Barahalikar.

One last question, can't we avoid JS policy for the dev app name check ?

Is it possible to validate the consumer developer app name in directly AssignMessage policy itself ? may be some <condition> tag ?

I was thinking to do the response altering and dev app name checking in single AssignMessage policy. Please let me know if that wont' work.

As of now since you only have 2 dev apps, you can avoid JS and simple use two Assign Message policies with Conditions something like,

<Condition>developer.app.name = 'xyz'</Condition>
<Condition>developer.app.name != 'xyz'</Condition>
<Condition>developer.app.name = 'abc'</Condition>

Hi @Siddharth Barahalikar,

Why we need two AssignMessage policies? Isn't possible to modify the existing response with one AssignMessage policy ?

I thought you want to change the target response for both dev apps. So I mentioned two AM policies.

Thanks @Siddharth Barahalikar for helping on this.