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