Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Warning
titleSafety First!

Because each request contains your API key, and may contain additional sensitive information, you should only process requests remotely over a secure connection (i.e. only use HTTPS)

 

The following example illustrates how to connect to the API using cURL.

Info
titleDownload the API SDK

The SDK includes an API processor that makes it super easy to work with the API.

Section
Column
width50%
Code Block
languagephp
titleConnecting Remotely with PHP
firstline1
linenumberstrue
<?php
// The URL to the API $api_url
require_once "blesta_api.php";

$user = "username";
$key = "key";
$url = "https://yourdomain.com/installpath/api/";

// API credentials
$api
_username
 =
"username"; $api_key = "key"; // The Model to request $model = "users"; // The method to request $method = "get"; // The response format $format = "json"; // All parameters to send $params = array( 'user_id'=>1 ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $api_url . $model . "/" . $method . "." . $format . "?" . http_build_query($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $api_username . ":" . $api_key); $result = curl_exec($ch); echo $result; ?>
Info
titleDownload the API SDK

The SDK includes an API processor that makes it super easy to work with the API.

...

 new BlestaApi($url, $user, $key);

$response = $api->get("users", "get", array('user_id' => 1));

print_r($response->response());
print_r($response->errors());
?>
Column
width50%
Code Block
languagebash
titleConnecting Remotely with cURL
curl https://yourdomain.com/installpath/api/users/get.json?user_id=1 -u username:key

Locally

Using the Command Line Interface

...