Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Load the access token previously obtained by this example: RSAP Union OAuth2
local jToken = chilkat.JsonObject.new()
local success = jToken:load_file("qa_data/tokens/rsapToken.json")
if not success then
print("Failed to load access token JSON.")
return
end
-- Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.auth_token = jToken:string_of("access_token")
-- For authentication, assuming both the client cert and access token are needed???
local cert = chilkat.Cert.new()
success = cert:load_from_file("qa_data/certs_and_keys/union_client_certificate.crt")
if not success then
print(cert.last_error_text)
return
end
local privKey = chilkat.PrivateKey.new()
success = privKey:load_any_format_file("qa_data/certs_and_keys/union_client_certificate.nopass.key", "")
if not success then
print(privKey.last_error_text)
return
end
-- 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:set_private_key(privKey)
if not success then
print(cert.last_error_text)
return
end
-- Tell HTTP to use the cert for client TLS certificate authentication.
success = http:set_ssl_client_cert(cert)
if not success then
print(http.last_error_text)
return
end
local sbResponseBody = chilkat.StringBuilder.new()
success = http:quick_get_sb("https://api-test.rsap.ca/members/status", sbResponseBody)
if not success then
print(http.last_error_text)
return
end
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(http.last_header)
print("Failed.")
return
end