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
(PureBasic) MedTunnel: Send Message with File AttachmentSee more MedTunnel ExamplesDemonstrates the MedTunnel SendMessage method to send a message with a file attachment to one or more recipients. For more information, see https://server.medtunnel.com/apidocs/html/M_MedTunnelMsg_Controllers_MessageController_SendMessage.htm
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkHttpRequest.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; 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" ; -F "file1=@qa_data/jpg/starfish.jpg" ; Use the following online tool to generate HTTP code from a CURL command ; Convert a cURL Command to HTTP Source Code req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpRequest::setCkHttpVerb(req, "POST") CkHttpRequest::setCkPath(req, "/MedTunnelMsg/api/Message/SendMessage") CkHttpRequest::setCkContentType(req, "multipart/form-data") CkHttpRequest::ckAddParam(req,"ApplicationId","yourApplicationId") CkHttpRequest::ckAddParam(req,"LocationId","yourLocationId") CkHttpRequest::ckAddParam(req,"MedTunnelId","yourMedTunnelId") CkHttpRequest::ckAddParam(req,"MedTunnelPassword","yourMedTunnelPassword") CkHttpRequest::ckAddParam(req,"To","recipientsMedTunnelId") CkHttpRequest::ckAddParam(req,"Body","Test") success = CkHttpRequest::ckAddFileForUpload2(req,"file1","qa_data/jpg/starfish.jpg","application/octet-stream") CkHttpRequest::ckAddHeader(req,"Expect","100-continue") resp.i = CkHttp::ckSynchronousRequest(http,"server.medtunnel.com",443,1,req) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(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.i = CkJsonObject::ckIntOf(jResp,"ReturnCode") ReturnCodeText.s = CkJsonObject::ckStringOf(jResp,"ReturnCodeText") Data.s = CkJsonObject::ckStringOf(jResp,"Data") ; Load the Data into another JSON object and parse.. jsonData.i = CkJsonObject::ckCreate() If jsonData.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(jsonData,Data) CkJsonObject::setCkEmitCompact(jsonData, 0) Debug CkJsonObject::ckEmit(jsonData) ; { ; "Id": 989448, ; "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:48:22 PM", ; "DisplayDateReceived": "04/29/2021 2:48 PM", ; "ViewCount": 0, ; "ViewedOn": "", ; "AttachmentCount": 1, ; "AttachmentNames": [ ; { ; "MessageId": 989448, ; "Id": 424857, ; "Name": "starfish.jpg.35910fe9-4118-414c-a845-4d092ca6e784", ; "DisplayName": "starfish.jpg", ; "Size": 6229, ; "WasViewed": false, ; "ViewedOn": "", ; "ViewCount": 0, ; "Location": "Default" ; } ; ], ; "AllRecipients": [ ; { ; "Id": 989448, ; "UserName": "...", ; "AccountId": 0, ; "AccountName": "...", ; "AccountTitle": "", ; "FirstName": "...", ; "LastName": "...", ; "EmailAddress": "", ; "LastSentOn": "", ; "SendCount": 0, ; "IsFavorite": false ; } ; ], ; "Status": 0, ; "ParentMessageId": 989448, ; "DistributionListId": 0, ; "DistributionListName": "", ; "BodyHistory": "", ; "ReadReceiptCallbackUrl": null, ; "SendGlobalNotifications": false ; } MessageId.i Name.s DisplayName.s Size.i WasViewed.i Location.s UserName.s AccountId.i AccountName.s AccountTitle.s FirstName.s LastName.s LastSentOn.s SendCount.i IsFavorite.i Id.i = CkJsonObject::ckIntOf(jsonData,"Id") FromUserId.i = CkJsonObject::ckIntOf(jsonData,"FromUserId") FromMailBoxId.i = CkJsonObject::ckIntOf(jsonData,"FromMailBoxId") FromUserType.i = CkJsonObject::ckIntOf(jsonData,"FromUserType") FromUserName.s = CkJsonObject::ckStringOf(jsonData,"FromUserName") FromUserFullName.s = CkJsonObject::ckStringOf(jsonData,"FromUserFullName") FromUserAccountName.s = CkJsonObject::ckStringOf(jsonData,"FromUserAccountName") FromUserAccountTitle.s = CkJsonObject::ckStringOf(jsonData,"FromUserAccountTitle") ToUserId.i = CkJsonObject::ckIntOf(jsonData,"ToUserId") ToUserType.i = CkJsonObject::ckIntOf(jsonData,"ToUserType") ToUserMailboxId.s = CkJsonObject::ckStringOf(jsonData,"ToUserMailboxId") ToUserName.s = CkJsonObject::ckStringOf(jsonData,"ToUserName") ToUserFullName.s = CkJsonObject::ckStringOf(jsonData,"ToUserFullName") EmailAddress.s = CkJsonObject::ckStringOf(jsonData,"EmailAddress") Password.s = CkJsonObject::ckStringOf(jsonData,"Password") Subject.s = CkJsonObject::ckStringOf(jsonData,"Subject") PatientMedTunnelId.s = CkJsonObject::ckStringOf(jsonData,"PatientMedTunnelId") Body.s = CkJsonObject::ckStringOf(jsonData,"Body") DateReceived.s = CkJsonObject::ckStringOf(jsonData,"DateReceived") DisplayDateReceived.s = CkJsonObject::ckStringOf(jsonData,"DisplayDateReceived") ViewCount.i = CkJsonObject::ckIntOf(jsonData,"ViewCount") ViewedOn.s = CkJsonObject::ckStringOf(jsonData,"ViewedOn") AttachmentCount.i = CkJsonObject::ckIntOf(jsonData,"AttachmentCount") Status.i = CkJsonObject::ckIntOf(jsonData,"Status") ParentMessageId.i = CkJsonObject::ckIntOf(jsonData,"ParentMessageId") DistributionListId.i = CkJsonObject::ckIntOf(jsonData,"DistributionListId") DistributionListName.s = CkJsonObject::ckStringOf(jsonData,"DistributionListName") BodyHistory.s = CkJsonObject::ckStringOf(jsonData,"BodyHistory") ReadReceiptCallbackUrl.s = CkJsonObject::ckStringOf(jsonData,"ReadReceiptCallbackUrl") SendGlobalNotifications.i = CkJsonObject::ckBoolOf(jsonData,"SendGlobalNotifications") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jsonData,"AttachmentNames") While i < count_i CkJsonObject::setCkI(jsonData, i) MessageId = CkJsonObject::ckIntOf(jsonData,"AttachmentNames[i].MessageId") Id = CkJsonObject::ckIntOf(jsonData,"AttachmentNames[i].Id") Name = CkJsonObject::ckStringOf(jsonData,"AttachmentNames[i].Name") DisplayName = CkJsonObject::ckStringOf(jsonData,"AttachmentNames[i].DisplayName") Size = CkJsonObject::ckIntOf(jsonData,"AttachmentNames[i].Size") WasViewed = CkJsonObject::ckBoolOf(jsonData,"AttachmentNames[i].WasViewed") ViewedOn = CkJsonObject::ckStringOf(jsonData,"AttachmentNames[i].ViewedOn") ViewCount = CkJsonObject::ckIntOf(jsonData,"AttachmentNames[i].ViewCount") Location = CkJsonObject::ckStringOf(jsonData,"AttachmentNames[i].Location") i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jsonData,"AllRecipients") While i < count_i CkJsonObject::setCkI(jsonData, i) Id = CkJsonObject::ckIntOf(jsonData,"AllRecipients[i].Id") UserName = CkJsonObject::ckStringOf(jsonData,"AllRecipients[i].UserName") AccountId = CkJsonObject::ckIntOf(jsonData,"AllRecipients[i].AccountId") AccountName = CkJsonObject::ckStringOf(jsonData,"AllRecipients[i].AccountName") AccountTitle = CkJsonObject::ckStringOf(jsonData,"AllRecipients[i].AccountTitle") FirstName = CkJsonObject::ckStringOf(jsonData,"AllRecipients[i].FirstName") LastName = CkJsonObject::ckStringOf(jsonData,"AllRecipients[i].LastName") EmailAddress = CkJsonObject::ckStringOf(jsonData,"AllRecipients[i].EmailAddress") LastSentOn = CkJsonObject::ckStringOf(jsonData,"AllRecipients[i].LastSentOn") SendCount = CkJsonObject::ckIntOf(jsonData,"AllRecipients[i].SendCount") IsFavorite = CkJsonObject::ckBoolOf(jsonData,"AllRecipients[i].IsFavorite") i = i + 1 Wend CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) CkJsonObject::ckDispose(jsonData) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.