Writing Robots

In the following, we will show how to write a robot that accesses a REST API that uses OAuth as its authentication mechanism. As an example, we will use the Twitter REST API to obtain the most recent statuses by the authenticating user and the users he or she follows.

Start Design Studio and create a new robot. Do not enter a URL in the wizard, as we will not be able to access the REST API before having authenticated. Add a new input variable of type OAuthCredentials. Type "Twitter" as service provider, enter the access token and access token secret that was obtained when we went through the user authorization process in the Management Console wizard, and enter the consumer key and consumer secret of the Twitter application.

After adding the variable, open the robot configuration by clicking the button. Click the "Configure..." button on the Basic tab. On the "All Loading" tab there is a "Credentials" option. Switch it from standard username/password authentication to OAuth and select the input variable that was just added.

Press OK in both dialogs. The robot has now been configured to use OAuth and will use the specified credentials when running in Design Studio. We can now start accessing Twitter's API. For instance, to see the most recent status updates by the authenticating user and the users he or she follows, we can access the URL http://api.twitter.com/1/statuses/home_timeline.xml. Enter that URL in the address bar of Design Studio and press Enter.

You should now see the XML that has been returned, containing the most recent statuses in the user's timeline, as above.

Next, we will look at how to use the credentials stored in the Management Console as input to the robot.