spectrumvoip/netsapiensclient

Simple cURL based PHP client for NetSapiens API

0.0.3 2024-09-14 02:07 UTC

This package is not auto-updated.

Last update: 2024-09-28 02:17:40 UTC


README

About

This PHP client is designed to interact with the NetSapiens V1 API. It provides a convenient way to authenticate and make API calls to NetSapiens services.

Installation

To install the NetSapiens PHP Client, use Composer:

composer require spectrumvoip/netsapiensclient

Basic Usage

Initialization

First, include the Composer autoloader in your PHP script:

require 'vendor/autoload.php';

Then, create an instance of the NetSapiensClient:

$nsclient = new \spectrumvoip\NetSapiensClient\NetSapiensClient('your-hostname.com');

Authentication

To authenticate with the NetSapiens API:

$nsclient->login($clientId, $clientSecret, $username, $password);

Replace $clientId, $clientSecret, $username, and $password with your actual credentials.

Making API Calls

GET Request Example

Here's an example of how to count the number of domains:

$params = [
    'format' => 'json',
    'object' => 'domain',
    'action' => 'count',
    'domain' => '*'
];

try {
    $response = $nsclient->ns_api_get($params);
    echo "Number of domains: " . $response['total'];
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

POST Request Example

To make a POST request:

$params = [
    'format' => 'json',
    'object' => 'user',
    'action' => 'create',
    // Add other necessary parameters
];

try {
    $response = $nsclient->ns_api_post($params);
    echo "User created successfully";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

Advanced Features

Token Refresh

The client automatically refreshes the access token when it's close to expiration. You don't need to manually refresh the token in most cases.

Masquerading

To masquerade as another user:

$masqueradeResponse = $nsclient->masquerade_token($uid, $accessToken);

Replace $uid with the user ID you want to masquerade as, and $accessToken with a valid access token.

Error Handling

The client throws exceptions for API errors and connection issues. Always wrap your API calls in try-catch blocks to handle potential errors gracefully.

API Reference

For a complete list of available API methods and their parameters, please refer to the NetSapiens API documentation.

Contributing

If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License.