I tried using the AssignMessage Policy below
<AssignMessage name="AssignMessage-3"> <AssignTo createNew="true" type="request">request1 </AssignTo> <Add> <QueryParams> <QueryParam name="ql">select password where username='{proxy.username}'</QueryParam> </QueryParams> </Add> <AssignVariable> <Name>request.verb</Name> <Value>GET</Value> </AssignVariable> <AssignVariable> <Name>target.url</Name> <Value>https://api.usergrid.com/nagashree.b/digitalbranch/appusers</Value> </AssignVariable> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> </AssignMessage>
Couldnt get it to work. Tried javascript callout on the target endpoint as well.Couldnt get that to work as well. Any pointers if i am missing something or doing something really stupid?
var username = context.getVariable("apigee.username"); var targeturl = "https://api.usergrid.com/nagashree.b/digitalbranch/appusers"; targeturl = targeturl+"?ql=select password where username='"+username+"'"; conte xt.setVariable('target.url', targeturl); context.setVariable('target.verb', 'GET');
Solved! Go to Solution.
Resolved it. Seems very silly, I had no content-type header set in the POST request :(. Lost close to 3 hours due to that.
The way you are setting target.url seem correct to me,
for Verb,
In AssignMessage polic attached to the TargetEndpoint [either pre or post flow], you could use <Set><Verb>POST|GET</Verb></Set> to set the verb to POST or GET.
Thanks. The Set option is fine. Now I have a new pbm. the {proxy.username} isnt resolving to a value
In the trace, the target.url is shown as https://api.usergrid.com/nagashree.b/digitalbranch/appusers?ql=select password where username='{proxy.username}'
The query parameter isnt getting set. Anything that needs to be doen for this?
This is my extract variables policy and the payload sent in the POST request.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1"> <DisplayName>Extract Variables 1</DisplayName> <FaultRules/> <Properties/> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <JSONPayload> <Variable name="username"> <JSONPath>$.username</JSONPath> </Variable> <Variable name="password"> <JSONPath>$.password</JSONPath> </Variable> </JSONPayload> <Source clearPayload="false">request</Source> <VariablePrefix></VariablePrefix> </ExtractVariables>
{ "username":"john.nash", "password":"John@123" }
Resolved it. Seems very silly, I had no content-type header set in the POST request :(. Lost close to 3 hours due to that.
@Nagashree B Thanks for sharing the root problem. I'm sure someone else will appreciate you saving them 3 hours 🙂