-1

I am trying to do a curl request to a google maps API using the following URL. When I do it from the browser I get back the right results but if I do it from a command line on the same machine I get an error (see below). What am I missing?

Curl request:

curl https://maps.googleapis.com/maps/api/directions/json?origin=San+Francisco,CA&destination=Mountain+View,CA&sensor=false&key=API_KEY

Output:

{
  "error_message" : "Invalid request. Missing the 'destination' parameter.",
  "routes" : [],
  "status" : "REQUEST_DENIED"
}
user2399453
  • 2,930
  • 5
  • 33
  • 60
  • Are you URL encoding the URL as described in [the documentation](https://developers.google.com/maps/web-services/overview#BuildingURLs)? – geocodezip Sep 03 '15 at 18:45
  • If the URL works as is from the browser shouldnt the same URL passed to curl work too? – user2399453 Sep 03 '15 at 18:47
  • related question: [How to urlencode data for curl command?](http://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command) – geocodezip Sep 03 '15 at 18:53

1 Answers1

2

When you use the ampercent & sign - you're actually breaking your command line. To fix it, type your URL between double quotes "<url>":

curl "https://maps.googleapis.com/maps/api/directions/json?origin=San+Francisco,CA&destination=Mountain+View,CA&sensor=false&key=API_KEY"
uri2x
  • 3,162
  • 1
  • 11
  • 25