curl examples

update 11/02/2014 – in process of updating and checking examples – but we know for sure that the Twitter examples are broken.


This post is a collection of many examples of using curl (from a terminal command line) to make API requests. The ones marked with* will run without passwords or api-keys. The responses will generally be in XML, JSON, or HTML

Some of these curl examples will have API keys, user names, and passwords. To run them, you’ll need to replace the keys with your own.

Also, when running from the command line, ampersands ‘&’ will need to be escaped by preceding them with a backslash, like \&

Other characters may need to be escaped, like:

%23 = #

%40 = @

Or you can wrap the entire URL is quotes like this:

curl "dict://"
tips for finding curl examples

Look in the address bar of your web browser. Copy the entire URL and run it in curl. It will respond with the ‘text’ version of the web page.

displaying JSON on the command line

The respond from curl is raw data. To format JSON data, pipe the output through python, like this:

curl dict:// | python -mjson.tool

curl dict://
Twitter search (broken)

Twtitter API now requires authentication and will not run from a single curl command, except by using widgets. See this post:*

See this post for details:*
curl API

Here’s an example of a typical API call which gets the weather in San Francisco. Note I have obscured the API-key.

curl -H "X-Mashape-Authorization: YOUR-MASHAPE-KEY" ""

Here’s the result:

[{"day_of_week":"Wed","high":"63","low":"47","condition":"Mostly Clear"},{"day_of_week":"Thu","high":"66","low":"50","condition":"Partly Cloudy"}]

[Note] more examples in tkzic/mashape

Here is an example of a request to the Thesaurus API




Here are two examples I just got to work using curl

curl -X POST  --data "botid=b0dafd24ee35a477&input=hello"

curl -X POST  --data "botid=b0dafd24ee35a477&input=Where are you?"
Here is the result for the second question
<result status="0" botid="b0dafd24ee35a477" custid="b3422b612633ac87"><input>Where are you?</input><that>I am in the computer at</that></result>
curl -X POST  --data "botid=b0dafd24ee35a477&input=hello"

curl -X POST  --data "botid=b0dafd24ee35a477&input=Where are you?"

curl -X POST  --data "botid=b0dafd24ee35a477&input=Lets play some music today."
Google speech API (may be broken – need to check the key)

This is an example of the curl command to run from the command line

the test.flac file is located in tkzic/speech – it contains a recording of the phrase “there are turtles wandering through the city”. If you click on the file it will play through audacity.

curl \
  --data-binary @test.flac \
  --header 'Content-type: audio/x-flac; rate=16000' \
  '' (may be broken)

Today I was finally able to get this working. Reading a Cosm (Pachube) feed from curl and from Max. Here is an example that works in curl: (replace API-KEY with actual key)


You can get JSON responses by leaving off the .xml extension or replacing it with .json

Its critical to use “key=…” not “X-ApiKey=…” like in the cosm documentation, or you will get permission errors from curl and Max. v3 API

Link to documentation:

Here is an example (minus the api-key) which searches for videos about cats and returns a JSON response

curl "" custom search API

Use this method to have a custom search which searches the whole web…

Here is an example of a search using this method with curl – note the API-KEY is removed

curl ""
Twitter streaming API (broken) simple search API*

Not really applicable to curl, but it shows something.

curl -A Mozilla
coastal wind data API (broken 11/2014)
with a specific lat/lon you can get results along the west coast of us - here's san francisco. This query returns all the current time points for SF

curl,-122.44\&fmt=json > sf.json 

lets try for santa cruz

curl,-122.03\&fmt=json > sc.json API*
very cool api that does phonetic spellings - works!!!!

curl\&alphabet=int-icao\&format=json API (PUT request)
This works as of 1/28/2013

curl -v --request PUT --data-binary @./abc.json --header "X-ApiKey: 96PqSh4rj7HzNif3rWms3SUhwaDFGUT0g"