Developer-friendly & type-safe Php SDK specifically catered to leverage juo/admin-api API.
Tip
To finish publishing your SDK you must run your first generation action.
The SDK relies on Composer to manage its dependencies.
To install the SDK first add the below to your composer.json file:
{
"repositories": [
{
"type": "github",
"url": "https://github.com/juo/admin-api-php.git"
}
],
"require": {
"juo/admin-api": "*"
}
}Then run the following command:
composer updatedeclare(strict_types=1);
require 'vendor/autoload.php';
use Juo\AdminAPI;
use Juo\AdminAPI\Models\Operations;
$sdk = AdminAPI\Juo::builder()
->setTenant('<value>')
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
$request = new Operations\GetCustomersRequest();
$responses = $sdk->customers->list(
request: $request
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}This SDK supports the following security scheme globally:
| Name | Type | Scheme |
|---|---|---|
adminApiKey |
apiKey | API key |
To authenticate with the API the adminApiKey parameter must be set when initializing the SDK. For example:
declare(strict_types=1);
require 'vendor/autoload.php';
use Juo\AdminAPI;
use Juo\AdminAPI\Models\Operations;
$sdk = AdminAPI\Juo::builder()
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->setTenant('<value>')
->build();
$request = new Operations\GetCustomersRequest();
$responses = $sdk->customers->list(
request: $request
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}Available methods
- list - Lists customers
- list - List schedule orders for a customer
- listAdjustments - List schedule adjustments for a customer
- postSchedulesAdjustments - Creates a schedule adjustment
- delete - Deletes a schedule adjustment
- list - Lists subscriptions
- update - Updates a subscription
- pause - Pauses an active subscription
- resume - Resumes a paused subscription
- cancel - Cancels an active/paused subscription
- reactivate - Reactivates a cancelled subscription
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned object will be a Generator instead of an individual response.
Working with generators is as simple as iterating over the responses in a foreach loop, and you can see an example below:
declare(strict_types=1);
require 'vendor/autoload.php';
use Juo\AdminAPI;
use Juo\AdminAPI\Models\Operations;
$sdk = AdminAPI\Juo::builder()
->setTenant('<value>')
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
$request = new Operations\GetCustomersRequest();
$responses = $sdk->customers->list(
request: $request
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Errors\APIException exception, which has the following properties:
| Property | Type | Description |
|---|---|---|
$message |
string | The error message |
$statusCode |
int | The HTTP status code |
$rawResponse |
?\Psr\Http\Message\ResponseInterface | The raw HTTP response |
$body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the list method throws the following exceptions:
| Error Type | Status Code | Content Type |
|---|---|---|
| Errors\APIException | 4XX, 5XX | */* |
declare(strict_types=1);
require 'vendor/autoload.php';
use Juo\AdminAPI;
use Juo\AdminAPI\Models\Operations;
$sdk = AdminAPI\Juo::builder()
->setTenant('<value>')
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
try {
$request = new Operations\GetCustomersRequest();
$responses = $sdk->customers->list(
request: $request
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}
} catch (Errors\APIException $e) {
// handle default exception
throw $e;
}The default server can be overridden globally using the setServerUrl(string $serverUrl) builder method when initializing the SDK client instance. For example:
declare(strict_types=1);
require 'vendor/autoload.php';
use Juo\AdminAPI;
use Juo\AdminAPI\Models\Operations;
$sdk = AdminAPI\Juo::builder()
->setServerURL('https://api.juo.io/admin/v1')
->setTenant('<value>')
->setSecurity(
'<YOUR_API_KEY_HERE>'
)
->build();
$request = new Operations\GetCustomersRequest();
$responses = $sdk->customers->list(
request: $request
);
foreach ($responses as $response) {
if ($response->statusCode === 200) {
// handle response
}
}This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.