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
(Lianja) 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
// This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loHttp = createobject("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" // -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 loReq = createobject("CkHttpRequest") loReq.HttpVerb = "POST" loReq.Path = "/MedTunnelMsg/api/Message/SendMessage" loReq.ContentType = "multipart/form-data" loReq.AddParam("ApplicationId","yourApplicationId") loReq.AddParam("LocationId","yourLocationId") loReq.AddParam("MedTunnelId","yourMedTunnelId") loReq.AddParam("MedTunnelPassword","yourMedTunnelPassword") loReq.AddParam("To","recipientsMedTunnelId") loReq.AddParam("Body","Test") llSuccess = loReq.AddFileForUpload2("file1","qa_data/jpg/starfish.jpg","application/octet-stream") loReq.AddHeader("Expect","100-continue") loResp = loHttp.SynchronousRequest("server.medtunnel.com",443,.T.,loReq) if (loHttp.LastMethodSuccess = .F.) then ? loHttp.LastErrorText release loHttp release loReq return endif loSbResponseBody = createobject("CkStringBuilder") loResp.GetBodySb(loSbResponseBody) loJResp = createobject("CkJsonObject") loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = .F. ? "Response Body:" ? loJResp.Emit() lnRespStatusCode = loResp.StatusCode ? "Response Status Code = " + str(lnRespStatusCode) if (lnRespStatusCode >= 400) then ? "Response Header:" ? loResp.Header ? "Failed." release loResp release loHttp release loReq release loSbResponseBody release loJResp return endif release loResp // 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 lnReturnCode = loJResp.IntOf("ReturnCode") lcReturnCodeText = loJResp.StringOf("ReturnCodeText") lcData = loJResp.StringOf("Data") // Load the Data into another JSON object and parse.. loJsonData = createobject("CkJsonObject") loJsonData.Load(lcData) loJsonData.EmitCompact = .F. ? loJsonData.Emit() // { // "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 // } lnId = loJsonData.IntOf("Id") lnFromUserId = loJsonData.IntOf("FromUserId") lnFromMailBoxId = loJsonData.IntOf("FromMailBoxId") lnFromUserType = loJsonData.IntOf("FromUserType") lcFromUserName = loJsonData.StringOf("FromUserName") lcFromUserFullName = loJsonData.StringOf("FromUserFullName") lcFromUserAccountName = loJsonData.StringOf("FromUserAccountName") lcFromUserAccountTitle = loJsonData.StringOf("FromUserAccountTitle") lnToUserId = loJsonData.IntOf("ToUserId") lnToUserType = loJsonData.IntOf("ToUserType") lcToUserMailboxId = loJsonData.StringOf("ToUserMailboxId") lcToUserName = loJsonData.StringOf("ToUserName") lcToUserFullName = loJsonData.StringOf("ToUserFullName") lcEmailAddress = loJsonData.StringOf("EmailAddress") lcPassword = loJsonData.StringOf("Password") lcSubject = loJsonData.StringOf("Subject") lcPatientMedTunnelId = loJsonData.StringOf("PatientMedTunnelId") lcBody = loJsonData.StringOf("Body") lcDateReceived = loJsonData.StringOf("DateReceived") lcDisplayDateReceived = loJsonData.StringOf("DisplayDateReceived") lnViewCount = loJsonData.IntOf("ViewCount") lcViewedOn = loJsonData.StringOf("ViewedOn") lnAttachmentCount = loJsonData.IntOf("AttachmentCount") lnStatus = loJsonData.IntOf("Status") lnParentMessageId = loJsonData.IntOf("ParentMessageId") lnDistributionListId = loJsonData.IntOf("DistributionListId") lcDistributionListName = loJsonData.StringOf("DistributionListName") lcBodyHistory = loJsonData.StringOf("BodyHistory") lcReadReceiptCallbackUrl = loJsonData.StringOf("ReadReceiptCallbackUrl") llSendGlobalNotifications = loJsonData.BoolOf("SendGlobalNotifications") i = 0 lnCount_i = loJsonData.SizeOfArray("AttachmentNames") do while i < lnCount_i loJsonData.I = i lnMessageId = loJsonData.IntOf("AttachmentNames[i].MessageId") lnId = loJsonData.IntOf("AttachmentNames[i].Id") lcName = loJsonData.StringOf("AttachmentNames[i].Name") lcDisplayName = loJsonData.StringOf("AttachmentNames[i].DisplayName") lnSize = loJsonData.IntOf("AttachmentNames[i].Size") llWasViewed = loJsonData.BoolOf("AttachmentNames[i].WasViewed") lcViewedOn = loJsonData.StringOf("AttachmentNames[i].ViewedOn") lnViewCount = loJsonData.IntOf("AttachmentNames[i].ViewCount") lcLocation = loJsonData.StringOf("AttachmentNames[i].Location") i = i + 1 enddo i = 0 lnCount_i = loJsonData.SizeOfArray("AllRecipients") do while i < lnCount_i loJsonData.I = i lnId = loJsonData.IntOf("AllRecipients[i].Id") lcUserName = loJsonData.StringOf("AllRecipients[i].UserName") lnAccountId = loJsonData.IntOf("AllRecipients[i].AccountId") lcAccountName = loJsonData.StringOf("AllRecipients[i].AccountName") lcAccountTitle = loJsonData.StringOf("AllRecipients[i].AccountTitle") lcFirstName = loJsonData.StringOf("AllRecipients[i].FirstName") lcLastName = loJsonData.StringOf("AllRecipients[i].LastName") lcEmailAddress = loJsonData.StringOf("AllRecipients[i].EmailAddress") lcLastSentOn = loJsonData.StringOf("AllRecipients[i].LastSentOn") lnSendCount = loJsonData.IntOf("AllRecipients[i].SendCount") llIsFavorite = loJsonData.BoolOf("AllRecipients[i].IsFavorite") i = i + 1 enddo release loHttp release loReq release loSbResponseBody release loJResp release loJsonData |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.