Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > FAQs > How can I use PHP to call the Rightscale management API?

How can I use PHP to call the Rightscale management API?

Background

This article explains how to utilize PHP along with the Curl PHP library in order to call the Rightscale management API (1.0) and make requests.

Answer

First, you will need to ensure that the Curl library for PHP is installed and that it is enabled and ready for use.

For more information on how to do this, please see the Curl PHP homepage -

http://www.php.net/manual/en/curl.setup.php

Once enabled, you can proceed with some of these examples.

Credentials
rs-api-creds.php
<?php

$rs_api = array(
	'version' => '1.0',
	'account_id' => 1234,
	'username' => "foo@bar.suf",
	'password' => "ubersecurepassword",
	'cookie_file' => '/tmp/rs_api_cookie.txt',
	//'cookie_file' => tempnam("/tmp", "rs_api"),
);

$rs_api['url'] = "https://my.rightscale.com/api/acct/".$rs_api['account_id'];

?>

This is the common credentials file to include with any of your PHP scripts that call the API. Ensure you have substituted the example account_id, username and password.

Login
rs-login.php
<?php

include 'rs-api-creds.php';

$rs_api['login_url'] = $rs_api['url']."/login?api_version=".$rs_api['version'];

$ch = curl_init($rs_api['login_url']);

curl_setopt($ch, CURLOPT_COOKIEJAR, $rs_api['cookie_file']);
curl_setopt($ch, CURLOPT_USERPWD,$rs_api['username'].':'.$rs_api['password']);

curl_exec($ch);
curl_close($ch);

?>

 

Get all servers
rs-get-servers.php
<?php

include 'rs-api-creds.php';

$url = $rs_api['url']."/servers?api_version=".$rs_api['version'];

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_COOKIEFILE, $rs_api['cookie_file']);

$output = curl_exec($ch);
curl_close($ch);

echo $output;

?>

More information

More information on the Curl PHP plugin: http://php.net/manual/en/book.curl.php

Support

RightScale customers can call Rightscale support on +1 (866) 787-2253 or send us an email at support@rightscale.com.
Alternatively, feel free to open a support incident by navigating to the Support -> Email link in the top right corner of the dashboard.

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

Tags

api

Classifications

This page has no classifications.

Announcements

None


© 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.