28

I keep getting a 401 response when I try to use authentication = ApiKeyAuthentication() in my ModelResource. I looked at Django Tastypie: How to Authenticate with API Key and he uses the get parameters to solve his issue. If I try use get parameters it picks up username but not api_key!

This works in browser

http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50

Sending via curl in terminal doesn't pickup api_key parameter

curl --dump-header - http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50

Why when using curl and appending 2 querystring parameters like ?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50 does it only pickup the first one. Is this not the correct way?

Community
  • 1
  • 1
darren
  • 18,845
  • 17
  • 60
  • 79

1 Answers1

85

Typing & in the command line means run the preceding command in the background (thanks @Maccesch), because of this anything after the & is being treated as a new command.

Try wrapping the url in quotes.

curl --dump-header - "http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50"

rockingskier
  • 9,066
  • 3
  • 40
  • 49
  • 3
    You are right, `&` means to run the preceeding command in the background. The string afterwards is considered a new command. – Maccesch Jun 11 '12 at 20:43
  • @Maccesch, cheers, I had a feeling it was that from when I was running a Apache Solr instance on my local VM. – rockingskier Jun 11 '12 at 21:16
  • 1
    Depending on OS and curl build, it might be single or double-quotes, too. (Had to use singles to get ODATA ?$top=1 to work on OSX.) – Jeremy Murray Dec 07 '15 at 23:06