Sample code for 30+ languages & platforms
PowerBuilder

MedTunnel: Get Mailbox Messages

See more MedTunnel Examples

Get the messages in the specified mailbox. The logged in user must have access to the mailbox.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
integer li_ReturnCode
string ls_ReturnCodeText
string ls_Data
oleobject loo_Jarr
oleobject loo_Json
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 j
integer li_Count_j
integer li_MessageId
string ls_Name
string ls_DisplayName
integer li_Size
integer li_WasViewed
string ls_Location
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 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 -X GET -k 
//         -H "Authorization:PutAuthorizationTokenHere" 
//         https://server.medtunnel.com/medtunnelmsg/api/Message/GetMailBoxMessages?MailBoxId=623&OnlyMessagesWithAttachments=false&LastMessageId=27812&StartRow=3&RowCount=25&UnReadOnly=false&IncludeAllMailBoxes=false

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

loo_Http.SetRequestHeader("Authorization","PutAuthorizationTokenHere")

// The mailbox id is contained in the JSON response from the login.
loo_Http.SetUrlVar("mailboxId","36965")
loo_Http.SetUrlVar("onlyMessagesWithAttachments","false")
loo_Http.SetUrlVar("lastMessageId","0")
loo_Http.SetUrlVar("startRow","0")
loo_Http.SetUrlVar("rowCount","25")
loo_Http.SetUrlVar("unReadOnly","false")
loo_Http.SetUrlVar("includeAllMailBoxes","false")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://server.medtunnel.com/medtunnelmsg/api/Message/GetMailBoxMessages?MailBoxId={$mailboxId}&OnlyMessagesWithAttachments={$onlyMessagesWithAttachments}&LastMessageId={$lastMessageId}&StartRow={$startRow}&RowCount={$rowCount}&UnReadOnly={$unReadOnly}&IncludeAllMailBoxes={$includeAllMailBoxes}",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

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_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    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": "[...]"
// }

// 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")

// The Data contains a JSON array, so load it into a Chilkat JSON array object.
loo_Jarr = create oleobject
li_rc = loo_Jarr.ConnectToNewObject("Chilkat.JsonArray")

loo_Jarr.Load(ls_Data)
loo_Jarr.EmitCompact = 0
Write-Debug loo_Jarr.Emit()

// Sample jsonArray content
// See sample code for parsing this content below..

// [
//   {
//     "Id": 989448,
//     "FromUserId": 36990,
//     "FromMailBoxId": 36965,
//     "FromUserType": 1,
//     "FromUserName": "joe@example",
//     "FromUserFullName": "Joe Smith",
//     "FromUserAccountName": "joe",
//     "FromUserAccountTitle": "Joe's Garage, Inc.",
//     "ToUserId": 36990,
//     "ToUserType": 1,
//     "ToUserMailboxId": "36965",
//     "ToUserName": "joe@example",
//     "ToUserFullName": "Joe Smith",
//     "EmailAddress": "",
//     "Password": "",
//     "Subject": "",
//     "PatientMedTunnelId": "",
//     "Body": "Test",
//     "DateReceived": "4/29/2021 2:48:22 PM",
//     "DisplayDateReceived": "Today  2:48 PM",
//     "ViewCount": 3,
//     "ViewedOn": "04/29/2021  2:52 PM",
//     "AttachmentCount": 1,
//     "AttachmentNames": [
//       {
//         "MessageId": 989448,
//         "Id": 424857,
//         "Name": "starfish.jpg.35910fe9-4118-414c-a845-4d092ca6e784",
//         "DisplayName": "starfish.jpg",
//         "Size": 6229,
//         "WasViewed": true,
//         "ViewedOn": "4/29/2021 2:52:19 PM",
//         "ViewCount": 1,
//         "Location": "Default"
//       }
//     ],
//     "AllRecipients": [
//       {
//         "Id": 989448,
//         "UserName": "joe@example",
//         "AccountId": 0,
//         "AccountName": "joe",
//         "AccountTitle": null,
//         "FirstName": "Joe",
//         "LastName": "Smith",
//         "EmailAddress": null,
//         "LastSentOn": null,
//         "SendCount": 0,
//         "IsFavorite": false
//       }
//     ],
//     "Status": 3,
//     "ParentMessageId": 989448,
//     "DistributionListId": 0,
//     "DistributionListName": "",
//     "BodyHistory": "",
//     "ReadReceiptCallbackUrl": null,
//     "SendGlobalNotifications": false
//   },
//   {
//     "Id": 989445,
//     "FromUserId": 36990,
//     "FromMailBoxId": 36965,
//     "FromUserType": 1,
//     "FromUserName": "joe@example",
//     "FromUserFullName": "Joe Smith",
//     "FromUserAccountName": "joe",
//     "FromUserAccountTitle": "Joe's Garage, Inc.",
//     "ToUserId": 36990,
//     "ToUserType": 1,
//     "ToUserMailboxId": "36965",
//     "ToUserName": "joe@example",
//     "ToUserFullName": "Joe Smith",
//     "EmailAddress": "",
//     "Password": "",
//     "Subject": "",
//     "PatientMedTunnelId": "",
//     "Body": "Test",
//     "DateReceived": "4/29/2021 2:47:36 PM",
//     "DisplayDateReceived": "Today  2:47 PM",
//     "ViewCount": 1,
//     "ViewedOn": "",
//     "AttachmentCount": 1,
//     "AttachmentNames": [
//       {
//         "MessageId": 989445,
//         "Id": 424856,
//         "Name": "starfish.jpg.c7dd04d8-43f2-4d86-af71-64f411bd5dfb",
//         "DisplayName": "starfish.jpg",
//         "Size": 6229,
//         "WasViewed": false,
//         "ViewedOn": "",
//         "ViewCount": 0,
//         "Location": "Default"
//       }
//     ],
//     "AllRecipients": [
//       {
//         "Id": 989445,
//         "UserName": "joe@example",
//         "AccountId": 0,
//         "AccountName": "joe",
//         "AccountTitle": null,
//         "FirstName": "Joe",
//         "LastName": "Smith",
//         "EmailAddress": null,
//         "LastSentOn": null,
//         "SendCount": 0,
//         "IsFavorite": false
//       }
//     ],
//     "Status": 3,
//     "ParentMessageId": 989445,
//     "DistributionListId": 0,
//     "DistributionListName": "",
//     "BodyHistory": "",
//     "ReadReceiptCallbackUrl": null,
//     "SendGlobalNotifications": false
//   },
//   {
//     "Id": 989436,
//     "FromUserId": 36990,
//     "FromMailBoxId": 36965,
//     "FromUserType": 1,
//     "FromUserName": "joe@example",
//     "FromUserFullName": "Joe Smith",
//     "FromUserAccountName": "joe",
//     "FromUserAccountTitle": "Joe's Garage, Inc.",
//     "ToUserId": 36990,
//     "ToUserType": 1,
//     "ToUserMailboxId": "36965",
//     "ToUserName": "joe@example",
//     "ToUserFullName": "Joe Smith",
//     "EmailAddress": "",
//     "Password": "",
//     "Subject": "",
//     "PatientMedTunnelId": "",
//     "Body": "Test",
//     "DateReceived": "4/29/2021 2:29:18 PM",
//     "DisplayDateReceived": "Today  2:29 PM",
//     "ViewCount": 1,
//     "ViewedOn": "",
//     "AttachmentCount": 0,
//     "AttachmentNames": [
//     ],
//     "AllRecipients": [
//       {
//         "Id": 989436,
//         "UserName": "joe@example",
//         "AccountId": 0,
//         "AccountName": "joe",
//         "AccountTitle": null,
//         "FirstName": "Joe",
//         "LastName": "Smith",
//         "EmailAddress": null,
//         "LastSentOn": null,
//         "SendCount": 0,
//         "IsFavorite": false
//       }
//     ],
//     "Status": 3,
//     "ParentMessageId": 989436,
//     "DistributionListId": 0,
//     "DistributionListName": "",
//     "BodyHistory": "",
//     "ReadReceiptCallbackUrl": null,
//     "SendGlobalNotifications": false
//   },
//   {
//     "Id": 989432,
//     "FromUserId": 36990,
//     "FromMailBoxId": 36965,
//     "FromUserType": 1,
//     "FromUserName": "joe@example",
//     "FromUserFullName": "Joe Smith",
//     "FromUserAccountName": "joe",
//     "FromUserAccountTitle": "Joe's Garage, Inc.",
//     "ToUserId": 36990,
//     "ToUserType": 1,
//     "ToUserMailboxId": "36965",
//     "ToUserName": "joe@example",
//     "ToUserFullName": "Joe Smith",
//     "EmailAddress": "",
//     "Password": "",
//     "Subject": "",
//     "PatientMedTunnelId": "",
//     "Body": "Test",
//     "DateReceived": "4/29/2021 2:25:27 PM",
//     "DisplayDateReceived": "Today  2:25 PM",
//     "ViewCount": 1,
//     "ViewedOn": "",
//     "AttachmentCount": 0,
//     "AttachmentNames": [
//     ],
//     "AllRecipients": [
//       {
//         "Id": 989432,
//         "UserName": "joe@example",
//         "AccountId": 0,
//         "AccountName": "joe",
//         "AccountTitle": null,
//         "FirstName": "Joe",
//         "LastName": "Smith",
//         "EmailAddress": null,
//         "LastSentOn": null,
//         "SendCount": 0,
//         "IsFavorite": false
//       }
//     ],
//     "Status": 3,
//     "ParentMessageId": 989432,
//     "DistributionListId": 0,
//     "DistributionListName": "",
//     "BodyHistory": "",
//     "ReadReceiptCallbackUrl": null,
//     "SendGlobalNotifications": false
//   },
//   {
//     "Id": 989251,
//     "FromUserId": 1,
//     "FromMailBoxId": 1,
//     "FromUserType": 100,
//     "FromUserName": "MedTunnel",
//     "FromUserFullName": "System Account",
//     "FromUserAccountName": "MedTunnel",
//     "FromUserAccountTitle": "",
//     "ToUserId": 36990,
//     "ToUserType": 1,
//     "ToUserMailboxId": "36965",
//     "ToUserName": "joe@example",
//     "ToUserFullName": "Joe Smith",
//     "EmailAddress": "",
//     "Password": "",
//     "Subject": "",
//     "PatientMedTunnelId": "",
//     "Body": "Welcome to MedTunnel! \r\n\r\nNow that you have signed up and activated your account, you are ready to start sending secure messages and documents using MedTunnel. So, what is the next step? It is recommended that you watch our training videos to learn how to use MedTunnel. There are 3 different client applications that you can use to access MedTunnel: \r\n\r\n1. If you are an administrator for a group, you should start out with the \u003cb\u003eGroup Account Administrators Video\u003c/b\u003e (\u003ca href=\"https://vimeo.com/104428633\" target=\"_blank\"\u003ehttps://vimeo.com/104428633\u003c/a\u003e). This video shows you the best practices for implementing MedTunnel into your practice, as well as how to add additional users. \r\n\r\n2. Next, watch the \u003cb\u003eMedTunnel Desktop App Video\u003c/b\u003e (\u003ca href=\"https://vimeo.com/103833157\" target=\"_blank\"\u003ehttps://vimeo.com/103833157\u003c/a\u003e). This video shows how to use the MedTunnel Desktop App - available as a free download for both PC and Mac. The Desktop App has 2 main features:\r\n\r\n\t- The \u003cb\u003ePrint-To-Send\u003c/b\u003e feature allows you to print from any application to a virtual printer to conveniently send documents.\r\n\r\n\t- The \u003cb\u003eAutoDownloader\u003c/b\u003e feature allows you to automatically download messages to your local hard drive for instant integration into your existing systems.\r\n\r\n3. Finally, there are two other client videos you can watch. The \u003cb\u003eWeb Client Demo Video\u003c/b\u003e (\u003ca href=\"https://vimeo.com/104434128\" target=\"_blank\"\u003ehttps://vimeo.com/104434128\u003c/a\u003e) shows you how to access MedTunnel via a browser on any device. The \u003cb\u003eMobile App Demo Video\u003c/b\u003e (\u003ca href=\"https://vimeo.com/104065728\" target=\"_blank\"\u003ehttps://vimeo.com/104065728\u003c/a\u003e) shows you how to access MedTunnel from our free Mobile App. \r\n\r\nHere are some useful links. \r\n\r\nMedTunnel Support Page: \u003ca href=\"http://www.medtunnel.com/support\" target=\"_blank\"\u003ehttp://www.medtunnel.com/support\u003c/a\u003e. The support page contains links to download the Desktop and Mobile Apps as well as other support related content. \r\n\r\nFAQs Page: \u003ca href=\"http://www.medtunnel.com/faqs\" target=\"_blank\"\u003ehttp://www.medtunnel.com/faqs\u003c/a\u003e. The FAQs page contains the most frequently asked questions about MedTunnel. \r\n\r\nIf you have any other questions or would like personalized service on using MedTunnel, you can contact us by simply logging in to your MedTunnel account and sending a message to MedTunnel ID: \u003cb\u003esupport\u003c/b\u003e.   You can also contact us by sending an email to support@medtunnel.com. \r\n\r\nAgain - Welcome to MedTunnel! We truly hope you enjoy your MedTunnel experience!\r\n\r\nThe MedTunnel Team\r\n",
//     "DateReceived": "4/28/2021 10:58:30 PM",
//     "DisplayDateReceived": "04/28/2021 10:58 PM",
//     "ViewCount": 1,
//     "ViewedOn": "",
//     "AttachmentCount": 0,
//     "AttachmentNames": [
//     ],
//     "AllRecipients": [
//       {
//         "Id": 989251,
//         "UserName": "joe@example",
//         "AccountId": 0,
//         "AccountName": "joe",
//         "AccountTitle": null,
//         "FirstName": "Joe",
//         "LastName": "Smith",
//         "EmailAddress": null,
//         "LastSentOn": null,
//         "SendCount": 0,
//         "IsFavorite": false
//       }
//     ],
//     "Status": 3,
//     "ParentMessageId": 989251,
//     "DistributionListId": 0,
//     "DistributionListName": "",
//     "BodyHistory": "",
//     "ReadReceiptCallbackUrl": null,
//     "SendGlobalNotifications": false
//   }
// ]

i = 0
li_Count_i = loo_Jarr.Size
do while i < li_Count_i
    loo_Json = loo_Jarr.ObjectAt(i)
    li_Id = loo_Json.IntOf("Id")
    li_FromUserId = loo_Json.IntOf("FromUserId")
    li_FromMailBoxId = loo_Json.IntOf("FromMailBoxId")
    li_FromUserType = loo_Json.IntOf("FromUserType")
    ls_FromUserName = loo_Json.StringOf("FromUserName")
    ls_FromUserFullName = loo_Json.StringOf("FromUserFullName")
    ls_FromUserAccountName = loo_Json.StringOf("FromUserAccountName")
    ls_FromUserAccountTitle = loo_Json.StringOf("FromUserAccountTitle")
    li_ToUserId = loo_Json.IntOf("ToUserId")
    li_ToUserType = loo_Json.IntOf("ToUserType")
    ls_ToUserMailboxId = loo_Json.StringOf("ToUserMailboxId")
    ls_ToUserName = loo_Json.StringOf("ToUserName")
    ls_ToUserFullName = loo_Json.StringOf("ToUserFullName")
    ls_EmailAddress = loo_Json.StringOf("EmailAddress")
    ls_Password = loo_Json.StringOf("Password")
    ls_Subject = loo_Json.StringOf("Subject")
    ls_PatientMedTunnelId = loo_Json.StringOf("PatientMedTunnelId")
    ls_Body = loo_Json.StringOf("Body")
    ls_DateReceived = loo_Json.StringOf("DateReceived")
    ls_DisplayDateReceived = loo_Json.StringOf("DisplayDateReceived")
    li_ViewCount = loo_Json.IntOf("ViewCount")
    ls_ViewedOn = loo_Json.StringOf("ViewedOn")
    li_AttachmentCount = loo_Json.IntOf("AttachmentCount")
    li_Status = loo_Json.IntOf("Status")
    li_ParentMessageId = loo_Json.IntOf("ParentMessageId")
    li_DistributionListId = loo_Json.IntOf("DistributionListId")
    ls_DistributionListName = loo_Json.StringOf("DistributionListName")
    ls_BodyHistory = loo_Json.StringOf("BodyHistory")
    ls_ReadReceiptCallbackUrl = loo_Json.StringOf("ReadReceiptCallbackUrl")
    li_SendGlobalNotifications = loo_Json.BoolOf("SendGlobalNotifications")
    j = 0
    li_Count_j = loo_Json.SizeOfArray("AttachmentNames")
    do while j < li_Count_j
        loo_Json.J = j
        li_MessageId = loo_Json.IntOf("AttachmentNames[j].MessageId")
        li_Id = loo_Json.IntOf("AttachmentNames[j].Id")
        ls_Name = loo_Json.StringOf("AttachmentNames[j].Name")
        ls_DisplayName = loo_Json.StringOf("AttachmentNames[j].DisplayName")
        li_Size = loo_Json.IntOf("AttachmentNames[j].Size")
        li_WasViewed = loo_Json.BoolOf("AttachmentNames[j].WasViewed")
        ls_ViewedOn = loo_Json.StringOf("AttachmentNames[j].ViewedOn")
        li_ViewCount = loo_Json.IntOf("AttachmentNames[j].ViewCount")
        ls_Location = loo_Json.StringOf("AttachmentNames[j].Location")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("AllRecipients")
    do while j < li_Count_j
        loo_Json.J = j
        li_Id = loo_Json.IntOf("AllRecipients[j].Id")
        ls_UserName = loo_Json.StringOf("AllRecipients[j].UserName")
        li_AccountId = loo_Json.IntOf("AllRecipients[j].AccountId")
        ls_AccountName = loo_Json.StringOf("AllRecipients[j].AccountName")
        ls_AccountTitle = loo_Json.StringOf("AllRecipients[j].AccountTitle")
        ls_FirstName = loo_Json.StringOf("AllRecipients[j].FirstName")
        ls_LastName = loo_Json.StringOf("AllRecipients[j].LastName")
        ls_EmailAddress = loo_Json.StringOf("AllRecipients[j].EmailAddress")
        ls_LastSentOn = loo_Json.StringOf("AllRecipients[j].LastSentOn")
        li_SendCount = loo_Json.IntOf("AllRecipients[j].SendCount")
        li_IsFavorite = loo_Json.BoolOf("AllRecipients[j].IsFavorite")
        j = j + 1
    loop
    destroy loo_Json
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp
destroy loo_Jarr