Visual FoxPro
Visual FoxPro
WhatsApp - Change a User Password
Demonstrates how to change the password for a WhatsApp Business API user account.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcUsername
LOCAL i
LOCAL lnCount_i
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = CreateObject('Chilkat.Http')
* Implements the following CURL command:
* curl -X PUT https://example.com/v1/users/username \
* -H "Authorization: Bearer your-auth-token" \
* -d '{"password": "new-password"}'
* The following JSON is sent in the request body.
* {
* "password": "new-password"
* }
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("password","new-password")
* Adds the "Authorization: Bearer your-auth-token" header.
loHttp.AuthToken = "your-auth-token"
loSbRequestBody = CreateObject('Chilkat.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpSb("PUT","https://example.com/v1/users/username",loSbRequestBody,"utf-8","application/json",loResp)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loResp
CANCEL
ENDIF
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loResp.Header
? "Failed."
RELEASE loHttp
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
ENDIF
* Sample JSON response:
* (Sample code for parsing the JSON response is shown below)
* {
* "users": [
* {
* "username": "username"
* }
* ]
* }
* Sample code for parsing the JSON response...
i = 0
lnCount_i = loJResp.SizeOfArray("users")
DO WHILE i < lnCount_i
loJResp.I = i
lcUsername = loJResp.StringOf("users[i].username")
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp