Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) SMSAPI - Create a ContactCreate a Contact For more information, see https://www.smsapi.com/docs?shell#create-contact
load ./chilkat.dll # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set http [new_CkHttp] # Implements the following CURL command: # curl -X POST https://api.smsapi.com/contacts -H "Authorization: Bearer token_api_oauth" \ # -d "phone_number=48500000000&email=bok@smsapi.com&first_name=Name&last_name=Last_name&gender=gender&description=description&city=city&groups=default" # Use the following online tool to generate HTTP code from a CURL command # Convert a cURL Command to HTTP Source Code set req [new_CkHttpRequest] CkHttpRequest_put_HttpVerb $req "POST" CkHttpRequest_put_Path $req "/contacts" CkHttpRequest_put_ContentType $req "application/x-www-form-urlencoded" CkHttpRequest_AddParam $req "phone_number" "48500000000" CkHttpRequest_AddParam $req "email" "bok@smsapi.com" CkHttpRequest_AddParam $req "first_name" "Name" CkHttpRequest_AddParam $req "last_name" "Last_name" CkHttpRequest_AddParam $req "gender" "gender" CkHttpRequest_AddParam $req "description" "description" CkHttpRequest_AddParam $req "city" "city" CkHttpRequest_AddParam $req "groups" "default" CkHttpRequest_AddHeader $req "Authorization" "Bearer token_api_oauth" # resp is a CkHttpResponse set resp [CkHttp_PostUrlEncoded $http "https://api.smsapi.com/contacts" $req] if {[CkHttp_get_LastMethodSuccess $http] == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkHttpRequest $req exit } set sbResponseBody [new_CkStringBuilder] CkHttpResponse_GetBodySb $resp $sbResponseBody set jResp [new_CkJsonObject] CkJsonObject_LoadSb $jResp $sbResponseBody CkJsonObject_put_EmitCompact $jResp 0 puts "Response Body:" puts [CkJsonObject_emit $jResp] set respStatusCode [CkHttpResponse_get_StatusCode $resp] puts "Response Status Code = $respStatusCode" if {$respStatusCode >= 400} then { puts "Response Header:" puts [CkHttpResponse_header $resp] puts "Failed." delete_CkHttpResponse $resp delete_CkHttp $http delete_CkHttpRequest $req delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp exit } delete_CkHttpResponse $resp # Sample JSON response: # (Sample code for parsing the JSON response is shown below) # { # "id": "5b802315a788494a04690d1d", # "first_name": "string", # "last_name": "string", # "phone_number": "48500000000", # "email": "bok@smsapi.com", # "gender": "gender", # "city": "city", # "date_created": "2018-08-24T17:24:05+02:00", # "date_updated": "2018-08-24T17:24:05+02:00", # "description": "description", # "groups": [ # { # "id": "59a3ca1fa78849062837cd0c", # "name": "default", # "date_created": "2017-08-28T09:45:35+02:00", # "date_updated": "2017-08-28T09:45:35+02:00", # "description": "", # "created_by": "username", # "idx": null, # "contact_expire_after": null, # "contacts_count": null # } # ] # } # Sample code for parsing the JSON response... # Use the following online tool to generate parsing code from sample JSON: # Generate Parsing Code from JSON set date_created [new_CkDtObj] set date_updated [new_CkDtObj] set id [CkJsonObject_stringOf $jResp "id"] set first_name [CkJsonObject_stringOf $jResp "first_name"] set last_name [CkJsonObject_stringOf $jResp "last_name"] set phone_number [CkJsonObject_stringOf $jResp "phone_number"] set email [CkJsonObject_stringOf $jResp "email"] set gender [CkJsonObject_stringOf $jResp "gender"] set city [CkJsonObject_stringOf $jResp "city"] CkJsonObject_DtOf $jResp "date_created" 0 $date_created CkJsonObject_DtOf $jResp "date_updated" 0 $date_updated set description [CkJsonObject_stringOf $jResp "description"] set i 0 set count_i [CkJsonObject_SizeOfArray $jResp "groups"] while {$i < $count_i} { CkJsonObject_put_I $jResp $i set id [CkJsonObject_stringOf $jResp "groups[i].id"] set name [CkJsonObject_stringOf $jResp "groups[i].name"] CkJsonObject_DtOf $jResp "groups[i].date_created" 0 $date_created CkJsonObject_DtOf $jResp "groups[i].date_updated" 0 $date_updated set description [CkJsonObject_stringOf $jResp "groups[i].description"] set created_by [CkJsonObject_stringOf $jResp "groups[i].created_by"] set idx [CkJsonObject_stringOf $jResp "groups[i].idx"] set contact_expire_after [CkJsonObject_stringOf $jResp "groups[i].contact_expire_after"] set contacts_count [CkJsonObject_stringOf $jResp "groups[i].contacts_count"] set i [expr $i + 1] } delete_CkHttp $http delete_CkHttpRequest $req delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp delete_CkDtObj $date_created delete_CkDtObj $date_updated |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.