I have an API endpoint set up in google cloud platform configured to work with a google cloud function and API Gateway, secured behind an API key. I am attempting to test this and incorporate it into my app, but I'm getting a really weird issue that I'm not sure what's going on.
Before I added the security of the API key I was able to simply run:
curl https://myendpoint.com/endpoint
and receive the appropriate response. I'd also get the same response if I put https://myendpoint.com/endpoint
into a browser URL bar.
However ever since I set up the API key, I am getting a weird issue where when I run curl, following the syntax provided by Google's documentation for using an API key:
curl https://myendpoint.com/endpoint?key=my_api_key
My terminal returns the following error:
zsh: no matches found: https://myendpoint.com/endpoint?key=my_api_key
Now if I run the curl command without the api key i get the correct response that I am unauthorized because I have no key.
But the weirdest part is, that if I copy and paste the URL including the API key into a browser, I get the expected result, and not this "no matches found" error!
So I guess it's something to do with zsh
or something? or curl specifically? Should I be passing the api key in a different way? maybe in a header?
Please help! Thanks
This has nothing to do with GCP. zsh is taking the ? to be a wildcard (glob) match, and it's not finding any matches.
You can simply put the whole URL in quotes to stop this globbing behavior:
curl "https://myendpoint.com/endpoint?key=my_api_key"
Or you can disable globbing in the shell if you don't want it.
See also: