Sample code for 30+ languages & platforms
Classic ASP

WhatsApp - Change a User Password

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

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

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

set http = Server.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"
' }

set json = Server.CreateObject("Chilkat.JsonObject")
success = json.UpdateString("password","new-password")

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

set sbRequestBody = Server.CreateObject("Chilkat.StringBuilder")
success = json.EmitSb(sbRequestBody)

set resp = Server.CreateObject("Chilkat.HttpResponse")
success = http.HttpSb("PUT","https://example.com/v1/users/username",sbRequestBody,"utf-8","application/json",resp)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
    Response.End
End If

set sbResponseBody = Server.CreateObject("Chilkat.StringBuilder")
success = resp.GetBodySb(sbResponseBody)
set jResp = Server.CreateObject("Chilkat.JsonObject")
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = 0

Response.Write "<pre>" & Server.HTMLEncode( "Response Body:") & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( jResp.Emit()) & "</pre>"

respStatusCode = resp.StatusCode
Response.Write "<pre>" & Server.HTMLEncode( "Response Status Code = " & respStatusCode) & "</pre>"
If (respStatusCode >= 400) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Response Header:") & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( resp.Header) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "Failed.") & "</pre>"
    Response.End
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...

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

%>
</body>
</html>