
I have a script in Flow Designer that is looking for active events with certain properties. It worked fine when I was looking for only one property, but now I want to look for two: "service" and "resource".
The properties are supposed to be separated with commas. I have some code that assembles the GET request like so:
var prop_name = 'propertyName=' + encodeURIComponent('service#en') + ',' + encodeURIComponent('resource#en');
var prop_value = 'propertyValue=' + encodeURIComponent(input['service']) + ',' + encodeURIComponent(input['resource']);
var prop_operator = 'propertyValueOperator=CONTAINS';
var _limit = 'offset=0&limit=500';
var _status = 'status=ACTIVE';
var apiRequest = http.request({
'endpoint': 'xMatters',
'path': '/api/xm/1/events?' + _status + '&' + prop_name + '&' + prop_value + '&' + prop_operator + '&' + _limit,
'method': 'GET'
});
The GET request returns 200 OK status but doesn't come up with the events I'm expecting to find. I think it's because the commas are being encoded to %2C:
GET https://mathworks-np.hosted.xmatters.com/api/xm/1/events?status=ACTIVE&propertyName=service%23en%2Cresource%23en&propertyValue=%5Bdatabase%5D%2Ciatttools-codecovdbtest-00&propertyValueOperator=CONTAINS&offset=0&limit=500
Would the comma encoding cause this request to fail? Is there a way I can get around it?
Comments
Please sign in to leave a comment.
Hi Michael,
I've seen this happen once before and suspect you may be running into something similar.
According to our documentation here:
https://help.xmatters.com/ondemand/xmodwelcome/integrationbuilder/scripting-reference.htm#IncomingRequestObject
you can force the URL encoding behavior and account for that comma by making it NOT auto-encode. This is the relevant bit:
**********************************
HTTP request object and write function
The following function returns an HTTP request object that can later be sent using its write() function:
The request function accepts a JavaScript object representing its options. The following table describes the available options:
Name of the pre-configured endpoint (case-sensitive) that the request is targeting.
Note: Slack endpoints require an additional function call to add the Slack token to API requests.
By default, the Integration Builder automatically encodes some characters in the URI (for example, spaces and slashes). This helps us standardize the URLs and create default configurations for our built-in and packaged integrations that have the best chance of succeeding wherever they find themselves.
However, we recommend that you override this default behavior and manually encode special characters. That way, you can make sure you're sending exactly the request you intend — and not leaving it up to a machine to interpret.
To override this behavior, include the
autoEncodeURI
property and set it tofalse
.*************************************
In short, if you are using http.request() then change this:
var request = http.request({
"endpoint": "xMatters",
"method": "GET",
"path": eventsURL
});
to:
var request=http.request({
"endpoint": "xMatters",
"autoEncodeURI": "false",
"method": "GET",
"path": eventsURL
});
and it should work fine.
Cheers!
Thanks Francois, that solved my problem. I added:
"autoEncodeURI":"false",
to the definition of the request variable.