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.
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.
<?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.
<?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); ?>
<?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 on the Curl PHP plugin: http://php.net/manual/en/book.curl.php
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.
© 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.