Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJToken
LOCAL oCert
LOCAL oPrivKey
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Load the access token previously obtained by this example: RSAP Union OAuth2
oJToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJToken:LoadFile("qa_data/tokens/rsapToken.json")
IF (nSuccess == 0)
? "Failed to load access token JSON."
oHttp:destroy()
oJToken:destroy()
RETURN
ENDIF
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
oHttp:AuthToken := oJToken:StringOf("access_token")
// For authentication, assuming both the client cert and access token are needed???
oCert := CreateObject("Chilkat.Cert")
nSuccess := oCert:LoadFromFile("qa_data/certs_and_keys/union_client_certificate.crt")
IF (nSuccess == 0)
? oCert:LastErrorText
oHttp:destroy()
oJToken:destroy()
oCert:destroy()
RETURN
ENDIF
oPrivKey := CreateObject("Chilkat.PrivateKey")
nSuccess := oPrivKey:LoadAnyFormatFile("qa_data/certs_and_keys/union_client_certificate.nopass.key", "")
IF (nSuccess == 0)
? oPrivKey:LastErrorText
oHttp:destroy()
oJToken:destroy()
oCert:destroy()
oPrivKey:destroy()
RETURN
ENDIF
// 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.
nSuccess := oCert:SetPrivateKey(oPrivKey)
IF (nSuccess == 0)
? oCert:LastErrorText
oHttp:destroy()
oJToken:destroy()
oCert:destroy()
oPrivKey:destroy()
RETURN
ENDIF
// Tell HTTP to use the cert for client TLS certificate authentication.
nSuccess := oHttp:SetSslClientCert(oCert)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJToken:destroy()
oCert:destroy()
oPrivKey:destroy()
RETURN
ENDIF
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://api-test.rsap.ca/members/status", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJToken:destroy()
oCert:destroy()
oPrivKey:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oHttp:destroy()
oJToken:destroy()
oCert:destroy()
oPrivKey:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
oHttp:destroy()
oJToken:destroy()
oCert:destroy()
oPrivKey:destroy()
oSbResponseBody:destroy()
oJResp:destroy()