If you have multiple parameters, a trailing ampersand will appear if only the first parameter is enabled. Also, an extra ampersand appears in front of the parameter if only the last one is selected. This is corrected by adding the following code to BuildUriPath(template, uriParameters):
// cleanup path
path = path.replace("&&", "&");
path = path.replace("/?", "?");