Search code examples
curlcommand-line-interfacewolframalpha

Using Wolfram Alpha from the command-line (cURL)


I'm having issues using Wolfram Alpha's web API with curl.

If I search http://api.wolframalpha.com/v2/query?input=TestQuery&appid=XXXXXXXXXXX (with my actual app ID of course) everything works. But If I use curl, I get an error. Something about the app ID missing?

curl -L http://api.wolframalpha.com/v2/query?input=TestQuery&appid=XXXXXXXXXXX

Here's the error:

<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='false'
    error='true'
    numpods='0'
    datatypes=''
    timedout=''
    timedoutpods=''
    timing='0.028'
    parsetiming='0.'
    parsetimedout='false'
    recalculate=''
    id=''
    host='http://www5b.wolframalpha.com'
    server='42'
    related=''
    version='2.6'
    profile='EnterDoQuery:0.,StartWrap:0.027632'>
 <error>
  <code>2</code>
  <msg>Appid missing</msg>
 </error>
</queryresult>

As you can tell, I'm someone of a novice with curl. I read somewhere I need to pass curl some sort of authentication, but I couldn't seem to figure out how.

Any help is appreciated.

Thanks


Solution

  • It should work with something like this:

    curl -dL 'http://api.wolframalpha.com/v2/query?input=TestQuery&appid=XXXX'

    Or if you want something else that has results to play with this end point is in their docs and should work for you:

    curl -dL 'http://api.wolframalpha.com/v2/query?input=pi&appid=XXXX'

    This site has some good examples of hitting other API's with various curl commands: http://blog.scottlowe.org/2014/02/19/using-curl-to-interact-with-a-restful-api/