PHP Client for Cloudesire API
If you are a vendor looking to integrate the syndicated provisioning progress, or just call the Cloudesire API from PHP, this page is for you.
The simplest way to interact with a REST API in PHP is leveraging the sendgrid/php-http-client.
To install the library, please take a look at the following upstream documentation:
A full example is available here.
Instantiate the client
To obtain an authenticated client you need to provide the URL of the Cloudesire
API ($api_url
) and a permanent authentication
token ($token
).
Avoid hard-coding those parameters, use environment variables or .ini files.
<?php
require __DIR__ . '/vendor/autoload.php';
$api_url = getenv('CLOUDESIRE_URL');
$token = getenv('CLOUDESIRE_TOKEN');
$headers = ['CMW-Auth-Token:' . $token];
$client = new SendGrid\Client($api_url, $headers);
Fetch subscription data
Every time you receive a syndication event, you need to fetch an updated view of the specific subscription resource.
$subscriptionId = 20000;
$response = $client->subscription()->_($subscriptionId)->get();
$subscription = json_decode($response->body(), true);
Set subscription endpoints
When the provisioning has been completed on your side, you need to provide the end-user endpoints to access your application.
$endpoints = [
[
'endpoint' => 'https://www.yourapp.com/login',
'description' => 'Login Page',
'category' => 'APP'
]
];
$response = $client->subscription()->_($subscriptionId)->endpoints()->post($endpoints);
Provide end-user instructions
Along with the end-user endpoints, you can provide textual instructions to the end-user.
$instructions = [
'en' => 'Demo English Instructions',
'it' => 'Istruzioni esemplificative in italiano'
];
$response = $client->subscription()->_($subscriptionId)->instructions()->post($instructions);
Set subscription deployment status to DEPLOYED
Once endpoints and end-user instructions, you can set the subscription deployment status to completed.
$requestBody = [
'deploymentStatus' => 'DEPLOYED'
];
$response = $client->subscription()->_($subscriptionId)->patch($requestBody);
Set subscription deployment status to UNDEPLOYED
When the subscription expires, you need to forbid user to access your application and confirm the undeployment of the subscription.
$requestBody = [
'deploymentStatus' => 'UNDEPLOYED'
];
$response = $client->subscription()->_($subscriptionId)->patch($requestBody);