Sample code for 30+ languages & platforms
Visual Basic 6.0

WhatsApp - Change a User Password

Demonstrates how to change the password for a WhatsApp Business API user account.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

Dim http As New ChilkatHttp

' 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"
' }

Dim json As New ChilkatJsonObject
success = json.UpdateString("password","new-password")

' Adds the "Authorization: Bearer your-auth-token" header.
http.AuthToken = "your-auth-token"

Dim sbRequestBody As New ChilkatStringBuilder
success = json.EmitSb(sbRequestBody)

Dim resp As New ChilkatHttpResponse
success = http.HttpSb("PUT","https://example.com/v1/users/username",sbRequestBody,"utf-8","application/json",resp)
If (success = 0) Then
    Debug.Print http.LastErrorText
    Exit Sub
End If

Dim sbResponseBody As New ChilkatStringBuilder
success = resp.GetBodySb(sbResponseBody)
Dim jResp As New ChilkatJsonObject
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = 0

Debug.Print "Response Body:"
Debug.Print jResp.Emit()

Dim respStatusCode As Long
respStatusCode = resp.StatusCode
Debug.Print "Response Status Code = " & respStatusCode
If (respStatusCode >= 400) Then
    Debug.Print "Response Header:"
    Debug.Print resp.Header
    Debug.Print "Failed."
    Exit Sub
End If

' Sample JSON response:
' (Sample code for parsing the JSON response is shown below)

' {
'   "users": [
'     {
'       "username": "username"
'     }
'   ]
' }

' Sample code for parsing the JSON response...

Dim username As String

Dim i As Long
i = 0
Dim count_i As Long
count_i = jResp.SizeOfArray("users")
Do While i < count_i
    jResp.I = i
    username = jResp.StringOf("users[i].username")
    i = i + 1
Loop