1

There's a few threads on this topic, but they haven't helped sadly. I'm using Curl, and a sample API call from: algorithmia - developers/getting-started/

Using the sample code provided I post this in Curl: curl -X POST -d '"MY_USERNAME"' -H 'Content-Type: application/json' -H 'Authorization: Simple MYKEY_SECRET' https://api.algorithmia.com/v1/algo/demo/Hello/0.1.1

I get this response:

curl: (6) Could not resolve host: application curl: (6) Could not resolve host: Simple curl: (6) Could not resolve host: simNBQHl {"error":{"message":"authorization required"}}

I've tried various edits (including double brackets, removing spacing at certain points) - this doesn't work, and at times gets an invalid json used response. Any insight into what obvious thing I may be missing?

I'm using Windows Command Prompt and pasting the text in after copying it from the website in case that may be a cause - although I've also tried pasting the code into notepad and then copying from there with no joy.

Thanks!

tbuckham
  • 11
  • 1
  • 4

1 Answers1

4

The Windows Command Prompt doesn't treat '' as an escaped string the way that UNIX prompts do, so it's reading application/json' as a URL argument, and application doesn't resolve as a DNS name (your first error) - see Escaping Double Quotes in Batch Script

You'd need to do something like:

curl -X POST -d """MY_USERNAME""" -H "Content-Type: application/json" -H "Authorization: Simple MYKEY_SECRET" "https://api.algorithmia.com/v1/algo/demo/Hello/0.1.1" 
Fiid
  • 1,852
  • 11
  • 22
  • 1
    Thanks - this works perfectly. I thought it might be something to do with the Windows Command Prompt - although trying other CLI tools on windows had the same issue. Is there a better CLI to use that avoids issues like the above? – tbuckham Jun 22 '17 at 07:58
  • Windows has PowerShell, and it's also possible to run some of the unix shells on Windows using Cygwin, which allows a lot of unixy/linuxy stuff to be compiled native. I prefer to use something like bash or zsh, but on Windows, I'm not sure which shell I'd choose; I don't use it too much. – Fiid Jun 22 '17 at 15:52