My requirement is to generate one authorization url where multiple queryparam are present which I am taking from custom attribute. One queryparam is "state" in which I want to assign GUID. which I have created using javascript policy.
here is my code:
function guid() { function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } var uuid = guid(); context.setVariable('response.header.x-apigee-uuid', uuid);
while using that uuid in queryparameter it is taking as null value.
Note: In trace the uuid is coming as read only. I am not sure whether this is the reason of taking the value as null.
Can you explain in more detail where you're expecting this guid to go? It seems you're setting it as a response header, so it goes back to your API Consumer as a header?
Yes, and.... the snapshot of the Trace (thank you for that) has an equals sign with a cross through it. This means the assignment did not happen.
Your policy (maybe the JavaScript) *tried* to assign that uuid to a header, but it did not succeed.
?why?
I suspect it may be because the JavaScript is running in the request flow, before the response message is available. You cannot assign to "response.header.ANYTHING" within a policy if the policy is attached in the request flow.
So.. make sure that
You may want to try assigning to request.queryparam.uuid , if you are expecting the upstream (backend) system to receive a uuid in a queryparam.
You may want to try assigning to request.header.uuid , if you are expecting the upstream (backend) system to receive a uuid in a request header.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |