sending Tweets with curl in Max,

Using and

Note: To get this project to work you’ll need a Twitter account. And you’ll need to set up a device (feed) at and a ‘zap’ at as directed in this post. It explains how to send tweets using triggers.

Also, you may notice delays due to the number of steps involved.

Looking for an easier way? Send Tweets using ruby:


folder: twitter-curl


  • tweetCurl5a.maxpat

[] download from here: – and add the path to the folder to Options | File Preferences in Max


  • feed id and api-key is embedded in max patch
  • you need a Twitter account
  • you need to set up a feed with twitter trigger, (as described here to get your own feed id, API-key, and authorize access to your Twitter account


  • Open the Max patch: tweetcurl5a.maxpat
  • enter your xively feed number and API-key into the fields (then press enter)
  • Type your Tweet text.
  • Press the big green button.

notes on curl

You can use curl for http: requests in Max by formatting the command line with [sprintf] and running it in []. There are a few idiosyncrasies – for example with escape sequences.

In tweetCurl5a.maxpat, the curl command is built in two sections:

  1. The request data is written to a data file /tmp/abc.json
  2.  the actual curl command is formatted and run from the command line. 
Here is the part of the patch which formats request data:

Using ‘quotes’ with [sprintf]

You’ll notice a lot of backslashes used in [sprintf]. This is done to preserve quotes. Normally a quote in [sprintf] indicates a string. Use 3 backslashes to escape a quote:


Passing arguments into [sprintf]

The [sprintf] code is obtuse because we are formatting JSON data. The resulting data looks like this:

{ "id":95586, "datastreams":[{ "current_value":"this is a tweet", "id": "tweet"}]}


Note that you can pass arguments into [sprintf] using %s – but if you are using a [textedit] to collect data from the user, you’ll need to use [tosymbol] to consolidate the text into a single symbol before passing into [sprintf]

Here’s the code which writes the formatted JSON data to a file:

The next step is to format the curl command, which will read the JSON data file and send an http: request to Here you can see the [sprintf] for this command.

Redirecting output to the Max window

At the very end of the [sprintf] you will see


This is the linux method to redirect error messages and standard output from [] to the same place, which in this case will be the Max window.

command line curl

By the way, here is what the curl command will look like on the command line

curl -v --request PUT --data-binary @/tmp/abc.json --header "X-ApiKey: abcdefg1234567" 2>&1


Note: The actual ApiKey above has been replaced with: abcdefg1234567 – so that you don’t accidentally send embarrassing Tweets from my account.