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) MedTunnel: Send Message Text OnlySee more MedTunnel ExamplesDemonstrates the MedTunnel SendMessage method to send a message to one or more recipients. For more information, see https://server.medtunnel.com/apidocs/html/M_MedTunnelMsg_Controllers_MessageController_SendMessage.htm
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 https://server.medtunnel.com/MedTunnelMsg/api/Message/SendMessage -X POST -k # -F "ApplicationId=yourApplicationId" -F "LocationId=yourLocationId" # -F "MedTunnelId=yourMedTunnelId" -F "MedTunnelPassword=yourMedTunnelPassword" # -F "To=recipientsMedTunnelId" # -F "Body=Test of SendMessage" # 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 "/MedTunnelMsg/api/Message/SendMessage" CkHttpRequest_put_ContentType $req "multipart/form-data" CkHttpRequest_AddParam $req "ApplicationId" "yourApplicationId" CkHttpRequest_AddParam $req "LocationId" "yourLocationId" CkHttpRequest_AddParam $req "MedTunnelId" "yourMedTunnelId" CkHttpRequest_AddParam $req "MedTunnelPassword" "yourMedTunnelPassword" CkHttpRequest_AddParam $req "To" "recipientsMedTunnelId" CkHttpRequest_AddParam $req "Body" "Test" # resp is a CkHttpResponse set resp [CkHttp_SynchronousRequest $http "server.medtunnel.com" 443 1 $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) # { # "ReturnCode": 1, # "ReturnCodeText": "Success", # "Data": "{\"Id\":989432,\"FromUserId\":36990,\"FromMailBoxId\":36965, ... \"SendGlobalNotifications\":false}" # } # 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 ReturnCode [CkJsonObject_IntOf $jResp "ReturnCode"] set ReturnCodeText [CkJsonObject_stringOf $jResp "ReturnCodeText"] set Data [CkJsonObject_stringOf $jResp "Data"] # Load the Data into another JSON object and parse.. set jsonData [new_CkJsonObject] CkJsonObject_Load $jsonData $Data CkJsonObject_put_EmitCompact $jsonData 0 puts [CkJsonObject_emit $jsonData] # { # "Id": 989436, # "FromUserId": 36990, # "FromMailBoxId": 36965, # "FromUserType": 0, # "FromUserName": "...", # "FromUserFullName": "...", # "FromUserAccountName": "...", # "FromUserAccountTitle": "...", # "ToUserId": 36990, # "ToUserType": 1, # "ToUserMailboxId": "36965", # "ToUserName": "...", # "ToUserFullName": "...", # "EmailAddress": "", # "Password": "", # "Subject": "", # "PatientMedTunnelId": "", # "Body": "Test", # "DateReceived": "4/29/2021 2:29:18 PM", # "DisplayDateReceived": "04/29/2021 2:29 PM", # "ViewCount": 0, # "ViewedOn": "", # "AttachmentCount": 0, # "AttachmentNames": [ # ], # "AllRecipients": [ # { # "Id": 989436, # "UserName": "...", # "AccountId": 0, # "AccountName": "...", # "AccountTitle": "", # "FirstName": "...", # "LastName": "...", # "EmailAddress": "", # "LastSentOn": "", # "SendCount": 0, # "IsFavorite": false # } # ], # "Status": 1, # "ParentMessageId": 989436, # "DistributionListId": 0, # "DistributionListName": "", # "BodyHistory": "", # "ReadReceiptCallbackUrl": null, # "SendGlobalNotifications": false # } # set Id [CkJsonObject_IntOf $jsonData "Id"] set FromUserId [CkJsonObject_IntOf $jsonData "FromUserId"] set FromMailBoxId [CkJsonObject_IntOf $jsonData "FromMailBoxId"] set FromUserType [CkJsonObject_IntOf $jsonData "FromUserType"] set FromUserName [CkJsonObject_stringOf $jsonData "FromUserName"] set FromUserFullName [CkJsonObject_stringOf $jsonData "FromUserFullName"] set FromUserAccountName [CkJsonObject_stringOf $jsonData "FromUserAccountName"] set FromUserAccountTitle [CkJsonObject_stringOf $jsonData "FromUserAccountTitle"] set ToUserId [CkJsonObject_IntOf $jsonData "ToUserId"] set ToUserType [CkJsonObject_IntOf $jsonData "ToUserType"] set ToUserMailboxId [CkJsonObject_stringOf $jsonData "ToUserMailboxId"] set ToUserName [CkJsonObject_stringOf $jsonData "ToUserName"] set ToUserFullName [CkJsonObject_stringOf $jsonData "ToUserFullName"] set EmailAddress [CkJsonObject_stringOf $jsonData "EmailAddress"] set Password [CkJsonObject_stringOf $jsonData "Password"] set Subject [CkJsonObject_stringOf $jsonData "Subject"] set PatientMedTunnelId [CkJsonObject_stringOf $jsonData "PatientMedTunnelId"] set Body [CkJsonObject_stringOf $jsonData "Body"] set DateReceived [CkJsonObject_stringOf $jsonData "DateReceived"] set DisplayDateReceived [CkJsonObject_stringOf $jsonData "DisplayDateReceived"] set ViewCount [CkJsonObject_IntOf $jsonData "ViewCount"] set ViewedOn [CkJsonObject_stringOf $jsonData "ViewedOn"] set AttachmentCount [CkJsonObject_IntOf $jsonData "AttachmentCount"] set Status [CkJsonObject_IntOf $jsonData "Status"] set ParentMessageId [CkJsonObject_IntOf $jsonData "ParentMessageId"] set DistributionListId [CkJsonObject_IntOf $jsonData "DistributionListId"] set DistributionListName [CkJsonObject_stringOf $jsonData "DistributionListName"] set BodyHistory [CkJsonObject_stringOf $jsonData "BodyHistory"] set ReadReceiptCallbackUrl [CkJsonObject_stringOf $jsonData "ReadReceiptCallbackUrl"] set SendGlobalNotifications [CkJsonObject_BoolOf $jsonData "SendGlobalNotifications"] set i 0 set count_i [CkJsonObject_SizeOfArray $jsonData "AttachmentNames"] while {$i < $count_i} { CkJsonObject_put_I $jsonData $i set i [expr $i + 1] } set i 0 set count_i [CkJsonObject_SizeOfArray $jsonData "AllRecipients"] while {$i < $count_i} { CkJsonObject_put_I $jsonData $i set Id [CkJsonObject_IntOf $jsonData "AllRecipients[i].Id"] set UserName [CkJsonObject_stringOf $jsonData "AllRecipients[i].UserName"] set AccountId [CkJsonObject_IntOf $jsonData "AllRecipients[i].AccountId"] set AccountName [CkJsonObject_stringOf $jsonData "AllRecipients[i].AccountName"] set AccountTitle [CkJsonObject_stringOf $jsonData "AllRecipients[i].AccountTitle"] set FirstName [CkJsonObject_stringOf $jsonData "AllRecipients[i].FirstName"] set LastName [CkJsonObject_stringOf $jsonData "AllRecipients[i].LastName"] set EmailAddress [CkJsonObject_stringOf $jsonData "AllRecipients[i].EmailAddress"] set LastSentOn [CkJsonObject_stringOf $jsonData "AllRecipients[i].LastSentOn"] set SendCount [CkJsonObject_IntOf $jsonData "AllRecipients[i].SendCount"] set IsFavorite [CkJsonObject_BoolOf $jsonData "AllRecipients[i].IsFavorite"] set i [expr $i + 1] } delete_CkHttp $http delete_CkHttpRequest $req delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp delete_CkJsonObject $jsonData |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.