Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

  // Load the access token previously obtained by this example:  RSAP Union OAuth2
  final jToken = CkJsonObject();
  try {
    jToken.loadFile('qa_data/tokens/rsapToken.json');
  } on ChilkatException {
    print('Failed to load access token JSON.');
    return;
  }

  // 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???
  final cert = CkCert();
  try {
    cert.loadFromFile('qa_data/certs_and_keys/union_client_certificate.crt');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final privKey = CkPrivateKey();
  try {
    privKey.loadAnyFormatFile('qa_data/certs_and_keys/union_client_certificate.nopass.key', '');
  } on ChilkatException catch (e) {
    print(e.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.
  try {
    cert.setPrivateKey(privKey);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Tell HTTP to use the cert for client TLS certificate authentication.
  try {
    http.setSslClientCert(cert);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final sbResponseBody = CkStringBuilder();
  try {
    http.quickGetSb('https://api-test.rsap.ca/members/status', sbResponseBody);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final jResp = CkJsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  print('Response Body:');
  print(jResp.emit());

  final respStatusCode = http.lastStatus;
  print('Response Status Code = $respStatusCode');
  if (respStatusCode >= 400) {
    print('Response Header:');
    print(http.lastHeader);
    print('Failed.');
    return;
  }
}