![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Swift) WhatsApp - Change a User PasswordDemonstrates how to change the password for a WhatsApp Business API user account. For more information, see https://developers.facebook.com/docs/whatsapp/api/users/manage
func chilkatTest() { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. let http = CkoHttp()! var success: Bool // 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" // } let json = CkoJsonObject()! json.update("password", value: "new-password") // Adds the "Authorization: Bearer your-auth-token" header. http.authToken = "your-auth-token" let sbRequestBody = CkoStringBuilder()! json.emitSb(sbRequestBody) var resp: CkoHttpResponse? = http.pTextSb("PUT", url: "https://example.com/v1/users/username", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false) if http.lastMethodSuccess == false { print("\(http.lastErrorText!)") return } let sbResponseBody = CkoStringBuilder()! resp!.getBodySb(sbResponseBody) let jResp = CkoJsonObject()! jResp.loadSb(sbResponseBody) jResp.emitCompact = false print("Response Body:") print("\(jResp.emit()!)") var respStatusCode: Int = resp!.statusCode.intValue print("Response Status Code = \(respStatusCode)") if respStatusCode >= 400 { print("Response Header:") print("\(resp!.header!)") print("Failed.") resp = nil return } resp = nil // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "users": [ // { // "username": "username" // } // ] // } // Sample code for parsing the JSON response... var username: String? var i: Int = 0 var count_i: Int = jResp.size(ofArray: "users").intValue while i < count_i { jResp.i = i username = jResp.string(of: "users[i].username") i = i + 1 } } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.