PHP
PHP
RSAP Union API - Get Members Status
See more _Miscellaneous_ Examples
Demonstrates how to use an OAuth2 access token for the RSAP Union API. Calls the endpoint to get the statuses of all union members.Chilkat PHP Downloads
<?php
use Chilkat2\Cert;
use Chilkat2\Http;
use Chilkat2\JsonObject;
use Chilkat2\PrivateKey;
use Chilkat2\StringBuilder;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$http = new Http();
// Load the access token previously obtained by this example: RSAP Union OAuth2
$jToken = new JsonObject();
try {
$jToken->LoadFile('qa_data/tokens/rsapToken.json');
} catch (\Chilkat2\Exception $e) {
echo "Failed to load access token JSON.\n";
exit;
}
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
$http->AuthToken = $jToken->StringOf('access_token');
// For authentication, assuming both the client cert and access token are needed???
$cert = new Cert();
try {
$cert->LoadFromFile('qa_data/certs_and_keys/union_client_certificate.crt');
$privKey = new PrivateKey();
$privKey->LoadAnyFormatFile('qa_data/certs_and_keys/union_client_certificate.nopass.key', '');
// Associate the private key with the cert.
// This will fail if the private key is not actually the correct one that corresponds to the public key stored within the cert.
$cert->SetPrivateKey($privKey);
// Tell HTTP to use the cert for client TLS certificate authentication.
$http->SetSslClientCert($cert);
$sbResponseBody = new StringBuilder();
$http->QuickGetSb('https://api-test.rsap.ca/members/status', $sbResponseBody);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$jResp = new JsonObject();
$jResp->LoadSb($sbResponseBody);
$jResp->EmitCompact = false;
echo "Response Body:\n";
echo $jResp->Emit(), "\n";
$respStatusCode = $http->LastStatus;
echo 'Response Status Code = ', $respStatusCode, "\n";
if ($respStatusCode >= 400) {
echo "Response Header:\n";
echo $http->LastHeader, "\n";
echo "Failed.\n";
exit;
}