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
(Delphi DLL) 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
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, HttpRequest, HttpResponse, StringBuilder, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; success: Boolean; req: HCkHttpRequest; resp: HCkHttpResponse; sbResponseBody: HCkStringBuilder; jResp: HCkJsonObject; respStatusCode: Integer; ReturnCode: Integer; ReturnCodeText: PWideChar; Data: PWideChar; jsonData: HCkJsonObject; UserName: PWideChar; AccountId: Integer; AccountName: PWideChar; AccountTitle: PWideChar; FirstName: PWideChar; LastName: PWideChar; LastSentOn: PWideChar; SendCount: Integer; IsFavorite: Boolean; Id: Integer; FromUserId: Integer; FromMailBoxId: Integer; FromUserType: Integer; FromUserName: PWideChar; FromUserFullName: PWideChar; FromUserAccountName: PWideChar; FromUserAccountTitle: PWideChar; ToUserId: Integer; ToUserType: Integer; ToUserMailboxId: PWideChar; ToUserName: PWideChar; ToUserFullName: PWideChar; EmailAddress: PWideChar; Password: PWideChar; Subject: PWideChar; PatientMedTunnelId: PWideChar; Body: PWideChar; DateReceived: PWideChar; DisplayDateReceived: PWideChar; ViewCount: Integer; ViewedOn: PWideChar; AttachmentCount: Integer; Status: Integer; ParentMessageId: Integer; DistributionListId: Integer; DistributionListName: PWideChar; BodyHistory: PWideChar; ReadReceiptCallbackUrl: PWideChar; SendGlobalNotifications: Boolean; i: Integer; count_i: Integer; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := CkHttp_Create(); // 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 req := CkHttpRequest_Create(); CkHttpRequest_putHttpVerb(req,'POST'); CkHttpRequest_putPath(req,'/MedTunnelMsg/api/Message/SendMessage'); CkHttpRequest_putContentType(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 := CkHttp_SynchronousRequest(http,'server.medtunnel.com',443,True,req); if (CkHttp_getLastMethodSuccess(http) = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; sbResponseBody := CkStringBuilder_Create(); CkHttpResponse_GetBodySb(resp,sbResponseBody); jResp := CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,False); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkJsonObject__emit(jResp)); respStatusCode := CkHttpResponse_getStatusCode(resp); Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); if (respStatusCode >= 400) then begin Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(CkHttpResponse__header(resp)); Memo1.Lines.Add('Failed.'); CkHttpResponse_Dispose(resp); Exit; end; CkHttpResponse_Dispose(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 ReturnCode := CkJsonObject_IntOf(jResp,'ReturnCode'); ReturnCodeText := CkJsonObject__stringOf(jResp,'ReturnCodeText'); Data := CkJsonObject__stringOf(jResp,'Data'); // Load the Data into another JSON object and parse.. jsonData := CkJsonObject_Create(); CkJsonObject_Load(jsonData,Data); CkJsonObject_putEmitCompact(jsonData,False); Memo1.Lines.Add(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 // } // Id := CkJsonObject_IntOf(jsonData,'Id'); FromUserId := CkJsonObject_IntOf(jsonData,'FromUserId'); FromMailBoxId := CkJsonObject_IntOf(jsonData,'FromMailBoxId'); FromUserType := CkJsonObject_IntOf(jsonData,'FromUserType'); FromUserName := CkJsonObject__stringOf(jsonData,'FromUserName'); FromUserFullName := CkJsonObject__stringOf(jsonData,'FromUserFullName'); FromUserAccountName := CkJsonObject__stringOf(jsonData,'FromUserAccountName'); FromUserAccountTitle := CkJsonObject__stringOf(jsonData,'FromUserAccountTitle'); ToUserId := CkJsonObject_IntOf(jsonData,'ToUserId'); ToUserType := CkJsonObject_IntOf(jsonData,'ToUserType'); ToUserMailboxId := CkJsonObject__stringOf(jsonData,'ToUserMailboxId'); ToUserName := CkJsonObject__stringOf(jsonData,'ToUserName'); ToUserFullName := CkJsonObject__stringOf(jsonData,'ToUserFullName'); EmailAddress := CkJsonObject__stringOf(jsonData,'EmailAddress'); Password := CkJsonObject__stringOf(jsonData,'Password'); Subject := CkJsonObject__stringOf(jsonData,'Subject'); PatientMedTunnelId := CkJsonObject__stringOf(jsonData,'PatientMedTunnelId'); Body := CkJsonObject__stringOf(jsonData,'Body'); DateReceived := CkJsonObject__stringOf(jsonData,'DateReceived'); DisplayDateReceived := CkJsonObject__stringOf(jsonData,'DisplayDateReceived'); ViewCount := CkJsonObject_IntOf(jsonData,'ViewCount'); ViewedOn := CkJsonObject__stringOf(jsonData,'ViewedOn'); AttachmentCount := CkJsonObject_IntOf(jsonData,'AttachmentCount'); Status := CkJsonObject_IntOf(jsonData,'Status'); ParentMessageId := CkJsonObject_IntOf(jsonData,'ParentMessageId'); DistributionListId := CkJsonObject_IntOf(jsonData,'DistributionListId'); DistributionListName := CkJsonObject__stringOf(jsonData,'DistributionListName'); BodyHistory := CkJsonObject__stringOf(jsonData,'BodyHistory'); ReadReceiptCallbackUrl := CkJsonObject__stringOf(jsonData,'ReadReceiptCallbackUrl'); SendGlobalNotifications := CkJsonObject_BoolOf(jsonData,'SendGlobalNotifications'); i := 0; count_i := CkJsonObject_SizeOfArray(jsonData,'AttachmentNames'); while i < count_i do begin CkJsonObject_putI(jsonData,i); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jsonData,'AllRecipients'); while i < count_i do begin CkJsonObject_putI(jsonData,i); Id := CkJsonObject_IntOf(jsonData,'AllRecipients[i].Id'); UserName := CkJsonObject__stringOf(jsonData,'AllRecipients[i].UserName'); AccountId := CkJsonObject_IntOf(jsonData,'AllRecipients[i].AccountId'); AccountName := CkJsonObject__stringOf(jsonData,'AllRecipients[i].AccountName'); AccountTitle := CkJsonObject__stringOf(jsonData,'AllRecipients[i].AccountTitle'); FirstName := CkJsonObject__stringOf(jsonData,'AllRecipients[i].FirstName'); LastName := CkJsonObject__stringOf(jsonData,'AllRecipients[i].LastName'); EmailAddress := CkJsonObject__stringOf(jsonData,'AllRecipients[i].EmailAddress'); LastSentOn := CkJsonObject__stringOf(jsonData,'AllRecipients[i].LastSentOn'); SendCount := CkJsonObject_IntOf(jsonData,'AllRecipients[i].SendCount'); IsFavorite := CkJsonObject_BoolOf(jsonData,'AllRecipients[i].IsFavorite'); i := i + 1; end; CkHttp_Dispose(http); CkHttpRequest_Dispose(req); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); CkJsonObject_Dispose(jsonData); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.