Perl
Perl
MedTunnel: Send Message Text Only
See more MedTunnel Examples
Demonstrates the MedTunnel SendMessage method to send a message to one or more recipients.Chilkat Perl Downloads
use chilkat();
$success = 0;
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
$http = chilkat::CkHttp->new();
# 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 = chilkat::CkHttpRequest->new();
$req->put_HttpVerb("POST");
$req->put_Path("/MedTunnelMsg/api/Message/SendMessage");
$req->put_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");
$resp = chilkat::CkHttpResponse->new();
$success = $http->HttpSReq("server.medtunnel.com",443,1,$req,$resp);
if ($success == 0) {
print $http->lastErrorText() . "\r\n";
exit;
}
$sbResponseBody = chilkat::CkStringBuilder->new();
$resp->GetBodySb($sbResponseBody);
$jResp = chilkat::CkJsonObject->new();
$jResp->LoadSb($sbResponseBody);
$jResp->put_EmitCompact(0);
print "Response Body:" . "\r\n";
print $jResp->emit() . "\r\n";
$respStatusCode = $resp->get_StatusCode();
print "Response Status Code = " . $respStatusCode . "\r\n";
if ($respStatusCode >= 400) {
print "Response Header:" . "\r\n";
print $resp->header() . "\r\n";
print "Failed." . "\r\n";
exit;
}
# 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 = $jResp->IntOf("ReturnCode");
$ReturnCodeText = $jResp->stringOf("ReturnCodeText");
$Data = $jResp->stringOf("Data");
# Load the Data into another JSON object and parse..
$jsonData = chilkat::CkJsonObject->new();
$jsonData->Load($Data);
$jsonData->put_EmitCompact(0);
print $jsonData->emit() . "\r\n";
# {
# "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 = $jsonData->IntOf("Id");
$FromUserId = $jsonData->IntOf("FromUserId");
$FromMailBoxId = $jsonData->IntOf("FromMailBoxId");
$FromUserType = $jsonData->IntOf("FromUserType");
$FromUserName = $jsonData->stringOf("FromUserName");
$FromUserFullName = $jsonData->stringOf("FromUserFullName");
$FromUserAccountName = $jsonData->stringOf("FromUserAccountName");
$FromUserAccountTitle = $jsonData->stringOf("FromUserAccountTitle");
$ToUserId = $jsonData->IntOf("ToUserId");
$ToUserType = $jsonData->IntOf("ToUserType");
$ToUserMailboxId = $jsonData->stringOf("ToUserMailboxId");
$ToUserName = $jsonData->stringOf("ToUserName");
$ToUserFullName = $jsonData->stringOf("ToUserFullName");
$EmailAddress = $jsonData->stringOf("EmailAddress");
$Password = $jsonData->stringOf("Password");
$Subject = $jsonData->stringOf("Subject");
$PatientMedTunnelId = $jsonData->stringOf("PatientMedTunnelId");
$Body = $jsonData->stringOf("Body");
$DateReceived = $jsonData->stringOf("DateReceived");
$DisplayDateReceived = $jsonData->stringOf("DisplayDateReceived");
$ViewCount = $jsonData->IntOf("ViewCount");
$ViewedOn = $jsonData->stringOf("ViewedOn");
$AttachmentCount = $jsonData->IntOf("AttachmentCount");
$Status = $jsonData->IntOf("Status");
$ParentMessageId = $jsonData->IntOf("ParentMessageId");
$DistributionListId = $jsonData->IntOf("DistributionListId");
$DistributionListName = $jsonData->stringOf("DistributionListName");
$BodyHistory = $jsonData->stringOf("BodyHistory");
$ReadReceiptCallbackUrl = $jsonData->stringOf("ReadReceiptCallbackUrl");
$SendGlobalNotifications = $jsonData->BoolOf("SendGlobalNotifications");
$i = 0;
$count_i = $jsonData->SizeOfArray("AttachmentNames");
while ($i < $count_i) {
$jsonData->put_I($i);
$i = $i + 1;
}
$i = 0;
$count_i = $jsonData->SizeOfArray("AllRecipients");
while ($i < $count_i) {
$jsonData->put_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;
}