Sample code for 30+ languages & platforms
Unicode C++

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 Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkCertW.h>
#include <CkPrivateKeyW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;

    // Load the access token previously obtained by this example:  RSAP Union OAuth2
    CkJsonObjectW jToken;
    success = jToken.LoadFile(L"qa_data/tokens/rsapToken.json");
    if (success == false) {
        wprintf(L"Failed to load access token JSON.\n");
        return;
    }

    // Adds the "Authorization: Bearer ACCESS_TOKEN" header.
    http.put_AuthToken(jToken.stringOf(L"access_token"));

    // For authentication, assuming both the client cert and access token are needed???
    CkCertW cert;
    success = cert.LoadFromFile(L"qa_data/certs_and_keys/union_client_certificate.crt");
    if (success == false) {
        wprintf(L"%s\n",cert.lastErrorText());
        return;
    }

    CkPrivateKeyW privKey;
    success = privKey.LoadAnyFormatFile(L"qa_data/certs_and_keys/union_client_certificate.nopass.key",L"");
    if (success == false) {
        wprintf(L"%s\n",privKey.lastErrorText());
        return;
    }

    // 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.
    success = cert.SetPrivateKey(privKey);
    if (success == false) {
        wprintf(L"%s\n",cert.lastErrorText());
        return;
    }

    // Tell HTTP to use the cert for client TLS certificate authentication.
    success = http.SetSslClientCert(cert);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    success = http.QuickGetSb(L"https://api-test.rsap.ca/members/status",sbResponseBody);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = http.get_LastStatus();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",http.lastHeader());
        wprintf(L"Failed.\n");
        return;
    }
    }