...
Warning |
---|
|
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 |
---|
title | Download the API SDK |
---|
|
The SDK includes an API processor that makes it super easy to work with the API. |
Section |
---|
Column |
---|
| Code Block |
---|
language | php |
---|
title | Connecting Remotely with PHP |
---|
firstline | 1 |
---|
linenumbers | true |
---|
| <?php
|
| // The URL to the API
$api_urlrequire_once "blesta_api.php";
$user = "username";
$key = "key";
$url = "https://yourdomain.com/installpath/api/";
|
| // API credentials
_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 |
---|
title | Download 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 |
---|
| Code Block |
---|
language | bash |
---|
title | Connecting Remotely with cURL |
---|
| curl https://yourdomain.com/installpath/api/users/get.json?user_id=1 -u username:key |
|
|
Locally
Using the Command Line Interface
...