Note: Please go to to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > RightScale API 1.0 > RightScale API 1.0 Examples > Authentication


Table of Contents


The RightScale API supports the use of a cookie/session. The first step in using the RightScale API is to login and get an authentication cookie which can then be used with subsequent requests within the session duration.

Note: API 1.0 uses GET (with HTTP Basic Authentication) and API 1.5 uses POST for authentication requests.

Login in to the API

Basic Example

Login to get a session cookie:

#!/bin/sh -e


# login to API 1.0
curl -H 'X-API-VERSION:1.0' -c mySavedCookies -u $RS_USER:$RS_PASS$RS_ACCOUNT/login 

Your session cookie should be saved now in the file, mySavedCookies, e.g.:

# Netscape HTTP Cookie File
# This file was generated by libcurl! Edit at your own risk.	TRUE	/	FALSE	0	rs_gbl	eNotkGtugkAUrX-lmWfHMMNwTZq0WBXxApJ6CS8Gh0HGchOGCBr_vZD27SRn7Z3s9QQhMEHWgRGIamA-QVOzCphIIwi9RkDQ_pYVpCiGQcgI8Kin6Rkbukx0iDGOIUIMQz0yVIiwjORIIhpV475PsP-sqqEh29cDvyNXZMeo9TqxV9P6C4tqTgIvEof9Dqs5vBVOXmysm_WdPKpuuTuK4n5nSqb-XEI4EzetObVHxHi7ho-FfEYosK9suAoE7qZ1Jd9r0Gd8N7RIDpY-61x1Ej9Ci5y4S9b6PLYKp7zr9nYqaY53Y1JJp-TC54d0ZVsdv55d3zmVnrYtp7h4H5S0g5I8zPopYJJUvH6bFVWUhFn_DCktmlwAUzOUfh7LQp4OdgZsHP9hHxW_JKKmYcrGtMjA6_UL_-ZxNA%3D%3D

Now the cookie file can be used with subsequent API calls, e.g. query a server:

# use the cookie to query server 223252001
curl -H 'X-API-VERSION:1.0' -b mySavedCookies$RS_ACCOUNT/servers/223252001

Advanced Example

#! /bin/sh -e


# by default API 1.0 is used unless rs_api_version=1.5 is set in env or ~/.rightscale/
# e.g. rs_api_config=1.5

# References

[ -e "$HOME"/.rightscale ] || ( mkdir -p "$HOME"/.rightscale && chmod -R 700 "$HOME"/.rightscale )

. "$HOME/.rightscale/"
. "$HOME/.rightscale/"

# get and store the cookie
if [ "$rs_api_version" = "1.5" ]; then
	echo "[API 1.5] POST: $url"
	result=$(curl -s -S -v -H 'X_API_VERSION: 1.5' -c "$rs_api_cookie" -X POST -d email="$rs_api_user" -d password="$rs_api_password" -d account_href=/api/accounts/$rs_api_account_id "$url" 2>&1)
	echo "[API 1.0] GET: $url"
	result=$(curl -s -S -v -c "$rs_api_cookie" -u "$rs_api_user":"$rs_api_password" "$url" 2>&1)

case $result in
	*'204 No Content'*)
		echo 'Login successful.'
		echo 'Login failed!'
		echo "$result"
		exit 1

Ruby Wrapper example

Each one of your Ruby programs will need to include the wrapper code, and a few other lines of code to create a new object, set your user, password and account.  Optionally, you can turn logging on or off.  For example:

require 'RightAPI.rb'
api =
api.log = true 
api.login(:username => 'user', :password => 'pass', :account => '1234')

Where username, password and account are substituted for their actual values.

You must to post a comment.
Last modified
21:57, 16 May 2013



This page has no classifications.



© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.