PowerBuilder
PowerBuilder
MedTunnel: Send Message Text Only
See more MedTunnel Examples
Demonstrates the MedTunnel SendMessage method to send a message to one or more recipients.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Req
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
integer li_ReturnCode
string ls_ReturnCodeText
string ls_Data
oleobject loo_JsonData
string ls_UserName
integer li_AccountId
string ls_AccountName
string ls_AccountTitle
string ls_FirstName
string ls_LastName
string ls_LastSentOn
integer li_SendCount
integer li_IsFavorite
integer li_Id
integer li_FromUserId
integer li_FromMailBoxId
integer li_FromUserType
string ls_FromUserName
string ls_FromUserFullName
string ls_FromUserAccountName
string ls_FromUserAccountTitle
integer li_ToUserId
integer li_ToUserType
string ls_ToUserMailboxId
string ls_ToUserName
string ls_ToUserFullName
string ls_EmailAddress
string ls_Password
string ls_Subject
string ls_PatientMedTunnelId
string ls_Body
string ls_DateReceived
string ls_DisplayDateReceived
integer li_ViewCount
string ls_ViewedOn
integer li_AttachmentCount
integer li_Status
integer li_ParentMessageId
integer li_DistributionListId
string ls_DistributionListName
string ls_BodyHistory
string ls_ReadReceiptCallbackUrl
integer li_SendGlobalNotifications
integer i
integer li_Count_i
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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
loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")
loo_Req.HttpVerb = "POST"
loo_Req.Path = "/MedTunnelMsg/api/Message/SendMessage"
loo_Req.ContentType = "multipart/form-data"
loo_Req.AddParam("ApplicationId","yourApplicationId")
loo_Req.AddParam("LocationId","yourLocationId")
loo_Req.AddParam("MedTunnelId","yourMedTunnelId")
loo_Req.AddParam("MedTunnelPassword","yourMedTunnelPassword")
loo_Req.AddParam("To","recipientsMedTunnelId")
loo_Req.AddParam("Body","Test")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpSReq("server.medtunnel.com",443,1,loo_Req,loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Req
destroy loo_Resp
return
end if
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Http
destroy loo_Req
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// 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
li_ReturnCode = loo_JResp.IntOf("ReturnCode")
ls_ReturnCodeText = loo_JResp.StringOf("ReturnCodeText")
ls_Data = loo_JResp.StringOf("Data")
// Load the Data into another JSON object and parse..
loo_JsonData = create oleobject
li_rc = loo_JsonData.ConnectToNewObject("Chilkat.JsonObject")
loo_JsonData.Load(ls_Data)
loo_JsonData.EmitCompact = 0
Write-Debug loo_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
// }
//
li_Id = loo_JsonData.IntOf("Id")
li_FromUserId = loo_JsonData.IntOf("FromUserId")
li_FromMailBoxId = loo_JsonData.IntOf("FromMailBoxId")
li_FromUserType = loo_JsonData.IntOf("FromUserType")
ls_FromUserName = loo_JsonData.StringOf("FromUserName")
ls_FromUserFullName = loo_JsonData.StringOf("FromUserFullName")
ls_FromUserAccountName = loo_JsonData.StringOf("FromUserAccountName")
ls_FromUserAccountTitle = loo_JsonData.StringOf("FromUserAccountTitle")
li_ToUserId = loo_JsonData.IntOf("ToUserId")
li_ToUserType = loo_JsonData.IntOf("ToUserType")
ls_ToUserMailboxId = loo_JsonData.StringOf("ToUserMailboxId")
ls_ToUserName = loo_JsonData.StringOf("ToUserName")
ls_ToUserFullName = loo_JsonData.StringOf("ToUserFullName")
ls_EmailAddress = loo_JsonData.StringOf("EmailAddress")
ls_Password = loo_JsonData.StringOf("Password")
ls_Subject = loo_JsonData.StringOf("Subject")
ls_PatientMedTunnelId = loo_JsonData.StringOf("PatientMedTunnelId")
ls_Body = loo_JsonData.StringOf("Body")
ls_DateReceived = loo_JsonData.StringOf("DateReceived")
ls_DisplayDateReceived = loo_JsonData.StringOf("DisplayDateReceived")
li_ViewCount = loo_JsonData.IntOf("ViewCount")
ls_ViewedOn = loo_JsonData.StringOf("ViewedOn")
li_AttachmentCount = loo_JsonData.IntOf("AttachmentCount")
li_Status = loo_JsonData.IntOf("Status")
li_ParentMessageId = loo_JsonData.IntOf("ParentMessageId")
li_DistributionListId = loo_JsonData.IntOf("DistributionListId")
ls_DistributionListName = loo_JsonData.StringOf("DistributionListName")
ls_BodyHistory = loo_JsonData.StringOf("BodyHistory")
ls_ReadReceiptCallbackUrl = loo_JsonData.StringOf("ReadReceiptCallbackUrl")
li_SendGlobalNotifications = loo_JsonData.BoolOf("SendGlobalNotifications")
i = 0
li_Count_i = loo_JsonData.SizeOfArray("AttachmentNames")
do while i < li_Count_i
loo_JsonData.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JsonData.SizeOfArray("AllRecipients")
do while i < li_Count_i
loo_JsonData.I = i
li_Id = loo_JsonData.IntOf("AllRecipients[i].Id")
ls_UserName = loo_JsonData.StringOf("AllRecipients[i].UserName")
li_AccountId = loo_JsonData.IntOf("AllRecipients[i].AccountId")
ls_AccountName = loo_JsonData.StringOf("AllRecipients[i].AccountName")
ls_AccountTitle = loo_JsonData.StringOf("AllRecipients[i].AccountTitle")
ls_FirstName = loo_JsonData.StringOf("AllRecipients[i].FirstName")
ls_LastName = loo_JsonData.StringOf("AllRecipients[i].LastName")
ls_EmailAddress = loo_JsonData.StringOf("AllRecipients[i].EmailAddress")
ls_LastSentOn = loo_JsonData.StringOf("AllRecipients[i].LastSentOn")
li_SendCount = loo_JsonData.IntOf("AllRecipients[i].SendCount")
li_IsFavorite = loo_JsonData.BoolOf("AllRecipients[i].IsFavorite")
i = i + 1
loop
destroy loo_Http
destroy loo_Req
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
destroy loo_JsonData