"Error executing REST request: Invalid uri " from API

arey yaar
Giga Guru

Unable to change the endpoint dynamically .

getting an error as API invalid.

var GetLocationDetails = Class.create();
GetLocationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
locDet: function(){


var arr = {};
var obj;
var loc = this.getParameter("sysparm_loc_det");

    var gr = new GlideRecord("cmn_location");
 gr.addQuery("sys_id",loc);
 gr .query();
 if(gr.next()){

 obj={
"name" : gr.name
	

};

	
}
	
	
function lat(origin,destination)
{
	

	var request = new sn_ws.RESTMessageV2();

			
request.setEndpoint('https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins='+origin+'&destinations='+destination+'&mode=driving&key=APIKEY');

		
 request.setHttpMethod('GET');

		 
	
var user = 'username;
var password = 'pws';

request.setBasicAuth(user,password);

request.setRequestHeader("Accept","application/json");

var response = request.execute();
gs.log(response.getBody());
}	
	
	var d=[];
	var e=[];
 var gre = new GlideRecord("cmn_location");
	gre.query();
	while(gre.next())
		{
		lat(obj.name,gre.name);	
		
        }

var data = new JSON().encode(fresh);
	 return data;
 
},
 type:'GetLocationDetails'
});
REST Msg Outbound - RESTMessageClient : Error executing REST request: Invalid uri ''https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&?origins=100+South+Charles+Street%2C+Baltimore%2CMD&key=APIKEY&destinations=2-10-1+Yurakucho%2C+Chiyoda-ku%2C+Tokyo': incorrect scheme: java.lang.IllegalArgumentException: Invalid uri ''https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&?origins=100+South+Charles+Street%2C+Baltimore%2CMD&key=APIKEY&destinations=2-10-1+Yurakucho%2C+Chiyoda-ku%2C+Tokyo': incorrect scheme: org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:222)
2 REPLIES 2

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

looking at the Google documentation:

Before you start developing with the Distance Matrix API, review the authentication requirements (you need an API key) and the API usage and billing information (you need to enable billing on your project).

Please check and provide a valid API key value in this part of code:

request.setEndpoint('https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins='+origin+'&destinations='+destination+'&mode=driving&key=APIKEY');

If I have answered your question, please mark my response as correct and/or helpful so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thank you

Cheers
Alberto

yes i have provided the api key still this isnt working