Hi, What is the apigee variable to access the whole path including querystring?
Like this variable request.querystring only returns the query string in the URL request and proxy.pathsuffix variable retruns only path suffix. Like that I'm looking for a variable with will return the path and querystring. Please find the example as follows.
Example:
http://bace-test.apigee.net/harmony/oauth2/access_token/abc/test?test=1
proxy.pathsuffix for this URL is /access_token (which is included in default.xml in proxy) and I wanted a variable to return abc/test?test=1 or /abc/test?test=1. I din't find any variable to return this one.
Please help me finding this. Thanks!
@Swapna You can use "message.uri" which would have abc/test?test=1&type=2.
Thanks @arghya das Tried this variable, it was giving the whole path without query string. It's giving as "harmony/oauth2/access_token/abc/test". I'm looking for the variable only which will return abc/test?test=1 or /abc/test?test=1.
@Swapna , Like @arghya das said, "message.uri" should work out of the box. It works for me in Apigee Cloud, Please see attached proxy & screenshot below.
@Swapna,
There does not seem to be any variable documented here, that you can use to retrieve the specific part of the string from the request URL. You may have to write Javascript, etc code to do the same.
I tried out locally and it worked for me.
Here's the snippet of the Javascript code:
// base path of the API var basePath = context.getVariable("proxy.basepath"); // request path of the API including query string var requestURI = context.getVariable("request.uri"); // Extract part of the string excluding base path var myResourcePath = requestURI.substr(basePath.length+1); context.setVariable("basePath", basePath); context.setVariable("requestURI", requestURI); context.setVariable("myResourcePath", myResourcePath);
This gave the output as shown below in my sample example:
basePath = /v1/sampleweather requestURI = /v1/sampleweather/forecastrss?w=12797282 myResourcePath = forecastrss?w=12797282
Hope this helps.
Regards,
Amar
var myVariable = context.getVariable("message.uri") should work.
I had already tried this:
var messageURI = context.getVariable("message.uri");
Here is the output I get
/v1/sampleweather/forecastrss?w=12797282
Both request.uri and message.uri contains the same values. Here is the definition of message.uri as documented here
message.uri | The complete URI path (following the domain URL) including query parameter |
The message.uri doesn't give the value what @Swapna trying to achieve.
If you use a simple javascript to remove the basepath from the messageURI variable, then you get the pathSuffix and the query params. Isn't that what she wanted ?
@Swapna can you try that out ?
I have already shared the Javascript code snippet that achieves what Swapna wants. Please see my answer below.