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
(C) 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
#include <C_CkHttp.h> #include <C_CkHttpRequest.h> #include <C_CkHttpResponse.h> #include <C_CkStringBuilder.h> #include <C_CkJsonObject.h> void ChilkatSample(void) { HCkHttp http; BOOL success; HCkHttpRequest req; HCkHttpResponse resp; HCkStringBuilder sbResponseBody; HCkJsonObject jResp; int respStatusCode; int ReturnCode; const char *ReturnCodeText; const char *Data; HCkJsonObject jsonData; const char *UserName; int AccountId; const char *AccountName; const char *AccountTitle; const char *FirstName; const char *LastName; const char *LastSentOn; int SendCount; BOOL IsFavorite; int Id; int FromUserId; int FromMailBoxId; int FromUserType; const char *FromUserName; const char *FromUserFullName; const char *FromUserAccountName; const char *FromUserAccountTitle; int ToUserId; int ToUserType; const char *ToUserMailboxId; const char *ToUserName; const char *ToUserFullName; const char *EmailAddress; const char *Password; const char *Subject; const char *PatientMedTunnelId; const char *Body; const char *DateReceived; const char *DisplayDateReceived; int ViewCount; const char *ViewedOn; int AttachmentCount; int Status; int ParentMessageId; int DistributionListId; const char *DistributionListName; const char *BodyHistory; const char *ReadReceiptCallbackUrl; BOOL SendGlobalNotifications; int i; int count_i; // 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) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkHttpRequest_Dispose(req); return; } sbResponseBody = CkStringBuilder_Create(); CkHttpResponse_GetBodySb(resp,sbResponseBody); jResp = CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,FALSE); printf("Response Body:\n"); printf("%s\n",CkJsonObject_emit(jResp)); respStatusCode = CkHttpResponse_getStatusCode(resp); printf("Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { printf("Response Header:\n"); printf("%s\n",CkHttpResponse_header(resp)); printf("Failed.\n"); CkHttpResponse_Dispose(resp); CkHttp_Dispose(http); CkHttpRequest_Dispose(req); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); return; } 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); printf("%s\n",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 // } // // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. 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) { CkJsonObject_putI(jsonData,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jsonData,"AllRecipients"); while (i < count_i) { 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; } CkHttp_Dispose(http); CkHttpRequest_Dispose(req); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); CkJsonObject_Dispose(jsonData); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.