Lianja
Lianja
WhatsApp - Get a User's Account Information
Demonstrates how to retrieve a user account by sending a GET request on the users endpoint.Chilkat Lianja Downloads
llSuccess = .F.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("CkHttp")
// Implements the following CURL command:
// curl -X GET https://example.com/v1/users/username \
// -H "Authorization: Bearer your-auth-token"
// Adds the "Authorization: Bearer your-auth-token" header.
loHttp.AuthToken = "your-auth-token"
loSbResponseBody = createobject("CkStringBuilder")
llSuccess = loHttp.QuickGetSb("https://example.com/v1/users/username",loSbResponseBody)
if (llSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
release loSbResponseBody
return
endif
loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
? "Response Header:"
? loHttp.LastHeader
? "Failed."
release loHttp
release loSbResponseBody
release loJResp
return
endif
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "users": [
// {
// "ROLES": "ROLE_ADMIN | ROLE_USER",
// "username": "username"
// }
// ]
// }
// Sample code for parsing the JSON response...
i = 0
lnCount_i = loJResp.SizeOfArray("users")
do while i < lnCount_i
loJResp.I = i
lcROLES = loJResp.StringOf("users[i].ROLES")
lcUsername = loJResp.StringOf("users[i].username")
i = i + 1
enddo
release loHttp
release loSbResponseBody
release loJResp