.NET Core C#
.NET Core C#
MedTunnel: Send Message Text Only
See more MedTunnel Examples
Demonstrates the MedTunnel SendMessage method to send a message to one or more recipients.Chilkat .NET Core C# Downloads
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Chilkat.Http http = new Chilkat.Http();
// 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
Chilkat.HttpRequest req = new Chilkat.HttpRequest();
req.HttpVerb = "POST";
req.Path = "/MedTunnelMsg/api/Message/SendMessage";
req.ContentType = "multipart/form-data";
req.AddParam("ApplicationId","yourApplicationId");
req.AddParam("LocationId","yourLocationId");
req.AddParam("MedTunnelId","yourMedTunnelId");
req.AddParam("MedTunnelPassword","yourMedTunnelPassword");
req.AddParam("To","recipientsMedTunnelId");
req.AddParam("Body","Test");
Chilkat.HttpResponse resp = new Chilkat.HttpResponse();
success = http.HttpSReq("server.medtunnel.com",443,true,req,resp);
if (success == false) {
Debug.WriteLine(http.LastErrorText);
return;
}
Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);
Chilkat.JsonObject jResp = new Chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;
Debug.WriteLine("Response Body:");
Debug.WriteLine(jResp.Emit());
int respStatusCode = resp.StatusCode;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
Debug.WriteLine("Response Header:");
Debug.WriteLine(resp.Header);
Debug.WriteLine("Failed.");
return;
}
// 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
int ReturnCode = jResp.IntOf("ReturnCode");
string ReturnCodeText = jResp.StringOf("ReturnCodeText");
string Data = jResp.StringOf("Data");
// Load the Data into another JSON object and parse..
Chilkat.JsonObject jsonData = new Chilkat.JsonObject();
jsonData.Load(Data);
jsonData.EmitCompact = false;
Debug.WriteLine(jsonData.Emit());
// {
// "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
// }
//
string UserName;
int AccountId;
string AccountName;
string AccountTitle;
string FirstName;
string LastName;
string LastSentOn;
int SendCount;
bool IsFavorite;
int Id = jsonData.IntOf("Id");
int FromUserId = jsonData.IntOf("FromUserId");
int FromMailBoxId = jsonData.IntOf("FromMailBoxId");
int FromUserType = jsonData.IntOf("FromUserType");
string FromUserName = jsonData.StringOf("FromUserName");
string FromUserFullName = jsonData.StringOf("FromUserFullName");
string FromUserAccountName = jsonData.StringOf("FromUserAccountName");
string FromUserAccountTitle = jsonData.StringOf("FromUserAccountTitle");
int ToUserId = jsonData.IntOf("ToUserId");
int ToUserType = jsonData.IntOf("ToUserType");
string ToUserMailboxId = jsonData.StringOf("ToUserMailboxId");
string ToUserName = jsonData.StringOf("ToUserName");
string ToUserFullName = jsonData.StringOf("ToUserFullName");
string EmailAddress = jsonData.StringOf("EmailAddress");
string Password = jsonData.StringOf("Password");
string Subject = jsonData.StringOf("Subject");
string PatientMedTunnelId = jsonData.StringOf("PatientMedTunnelId");
string Body = jsonData.StringOf("Body");
string DateReceived = jsonData.StringOf("DateReceived");
string DisplayDateReceived = jsonData.StringOf("DisplayDateReceived");
int ViewCount = jsonData.IntOf("ViewCount");
string ViewedOn = jsonData.StringOf("ViewedOn");
int AttachmentCount = jsonData.IntOf("AttachmentCount");
int Status = jsonData.IntOf("Status");
int ParentMessageId = jsonData.IntOf("ParentMessageId");
int DistributionListId = jsonData.IntOf("DistributionListId");
string DistributionListName = jsonData.StringOf("DistributionListName");
string BodyHistory = jsonData.StringOf("BodyHistory");
string ReadReceiptCallbackUrl = jsonData.StringOf("ReadReceiptCallbackUrl");
bool SendGlobalNotifications = jsonData.BoolOf("SendGlobalNotifications");
int i = 0;
int count_i = jsonData.SizeOfArray("AttachmentNames");
while (i < count_i) {
jsonData.I = i;
i = i + 1;
}
i = 0;
count_i = jsonData.SizeOfArray("AllRecipients");
while (i < count_i) {
jsonData.I = i;
Id = jsonData.IntOf("AllRecipients[i].Id");
UserName = jsonData.StringOf("AllRecipients[i].UserName");
AccountId = jsonData.IntOf("AllRecipients[i].AccountId");
AccountName = jsonData.StringOf("AllRecipients[i].AccountName");
AccountTitle = jsonData.StringOf("AllRecipients[i].AccountTitle");
FirstName = jsonData.StringOf("AllRecipients[i].FirstName");
LastName = jsonData.StringOf("AllRecipients[i].LastName");
EmailAddress = jsonData.StringOf("AllRecipients[i].EmailAddress");
LastSentOn = jsonData.StringOf("AllRecipients[i].LastSentOn");
SendCount = jsonData.IntOf("AllRecipients[i].SendCount");
IsFavorite = jsonData.BoolOf("AllRecipients[i].IsFavorite");
i = i + 1;
}