Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Bitfinex v2 REST
Bluzone
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
MedTunnel

MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
Trello
Twilio
Twitter
UniPin
VoiceBase
Vonage
Walmart
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yousign
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(DataFlex) MedTunnel: Send Message with File Attachment

See more MedTunnel Examples

Demonstrates the MedTunnel SendMessage method to send a message with a file attachment to one or more recipients.

For more information, see https://server.medtunnel.com/apidocs/html/M_MedTunnelMsg_Controllers_MessageController_SendMessage.htm

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vReq
    Handle hoReq
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    Integer iReturnCode
    String sReturnCodeText
    String sData
    Handle hoJsonData
    Integer iMessageId
    String sName
    String sDisplayName
    Integer iSize
    Boolean iWasViewed
    String sLocation
    String sUserName
    Integer iAccountId
    String sAccountName
    String sAccountTitle
    String sFirstName
    String sLastName
    String sLastSentOn
    Integer iSendCount
    Boolean iIsFavorite
    Integer iId
    Integer iFromUserId
    Integer iFromMailBoxId
    Integer iFromUserType
    String sFromUserName
    String sFromUserFullName
    String sFromUserAccountName
    String sFromUserAccountTitle
    Integer iToUserId
    Integer iToUserType
    String sToUserMailboxId
    String sToUserName
    String sToUserFullName
    String sEmailAddress
    String sPassword
    String sSubject
    String sPatientMedTunnelId
    String sBody
    String sDateReceived
    String sDisplayDateReceived
    Integer iViewCount
    String sViewedOn
    Integer iAttachmentCount
    Integer iStatus
    Integer iParentMessageId
    Integer iDistributionListId
    String sDistributionListName
    String sBodyHistory
    String sReadReceiptCallbackUrl
    Boolean iSendGlobalNotifications
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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"
    //         -F "file1=@qa_data/jpg/starfish.jpg"

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

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Set ComHttpVerb Of hoReq To "POST"
    Set ComPath Of hoReq To "/MedTunnelMsg/api/Message/SendMessage"
    Set ComContentType Of hoReq To "multipart/form-data"

    Send ComAddParam To hoReq "ApplicationId" "yourApplicationId"
    Send ComAddParam To hoReq "LocationId" "yourLocationId"
    Send ComAddParam To hoReq "MedTunnelId" "yourMedTunnelId"
    Send ComAddParam To hoReq "MedTunnelPassword" "yourMedTunnelPassword"
    Send ComAddParam To hoReq "To" "recipientsMedTunnelId"
    Send ComAddParam To hoReq "Body" "Test"

    Get ComAddFileForUpload2 Of hoReq "file1" "qa_data/jpg/starfish.jpg" "application/octet-stream" To iSuccess

    Send ComAddHeader To hoReq "Expect" "100-continue"

    Get pvComObject of hoReq to vReq
    Get ComSynchronousRequest Of hoHttp "server.medtunnel.com" 443 True vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    Get ComIntOf Of hoJResp "ReturnCode" To iReturnCode
    Get ComStringOf Of hoJResp "ReturnCodeText" To sReturnCodeText
    Get ComStringOf Of hoJResp "Data" To sData

    // Load the Data into another JSON object and parse..
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonData
    If (Not(IsComObjectCreated(hoJsonData))) Begin
        Send CreateComObject of hoJsonData
    End
    Get ComLoad Of hoJsonData sData To iSuccess
    Set ComEmitCompact Of hoJsonData To False
    Get ComEmit Of hoJsonData To sTemp1
    Showln sTemp1

    // {
    //   "Id": 989448,
    //   "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:48:22 PM",
    //   "DisplayDateReceived": "04/29/2021  2:48 PM",
    //   "ViewCount": 0,
    //   "ViewedOn": "",
    //   "AttachmentCount": 1,
    //   "AttachmentNames": [
    //     {
    //       "MessageId": 989448,
    //       "Id": 424857,
    //       "Name": "starfish.jpg.35910fe9-4118-414c-a845-4d092ca6e784",
    //       "DisplayName": "starfish.jpg",
    //       "Size": 6229,
    //       "WasViewed": false,
    //       "ViewedOn": "",
    //       "ViewCount": 0,
    //       "Location": "Default"
    //     }
    //   ],
    //   "AllRecipients": [
    //     {
    //       "Id": 989448,
    //       "UserName": "...",
    //       "AccountId": 0,
    //       "AccountName": "...",
    //       "AccountTitle": "",
    //       "FirstName": "...",
    //       "LastName": "...",
    //       "EmailAddress": "",
    //       "LastSentOn": "",
    //       "SendCount": 0,
    //       "IsFavorite": false
    //     }
    //   ],
    //   "Status": 0,
    //   "ParentMessageId": 989448,
    //   "DistributionListId": 0,
    //   "DistributionListName": "",
    //   "BodyHistory": "",
    //   "ReadReceiptCallbackUrl": null,
    //   "SendGlobalNotifications": false
    // }

    Get ComIntOf Of hoJsonData "Id" To iId
    Get ComIntOf Of hoJsonData "FromUserId" To iFromUserId
    Get ComIntOf Of hoJsonData "FromMailBoxId" To iFromMailBoxId
    Get ComIntOf Of hoJsonData "FromUserType" To iFromUserType
    Get ComStringOf Of hoJsonData "FromUserName" To sFromUserName
    Get ComStringOf Of hoJsonData "FromUserFullName" To sFromUserFullName
    Get ComStringOf Of hoJsonData "FromUserAccountName" To sFromUserAccountName
    Get ComStringOf Of hoJsonData "FromUserAccountTitle" To sFromUserAccountTitle
    Get ComIntOf Of hoJsonData "ToUserId" To iToUserId
    Get ComIntOf Of hoJsonData "ToUserType" To iToUserType
    Get ComStringOf Of hoJsonData "ToUserMailboxId" To sToUserMailboxId
    Get ComStringOf Of hoJsonData "ToUserName" To sToUserName
    Get ComStringOf Of hoJsonData "ToUserFullName" To sToUserFullName
    Get ComStringOf Of hoJsonData "EmailAddress" To sEmailAddress
    Get ComStringOf Of hoJsonData "Password" To sPassword
    Get ComStringOf Of hoJsonData "Subject" To sSubject
    Get ComStringOf Of hoJsonData "PatientMedTunnelId" To sPatientMedTunnelId
    Get ComStringOf Of hoJsonData "Body" To sBody
    Get ComStringOf Of hoJsonData "DateReceived" To sDateReceived
    Get ComStringOf Of hoJsonData "DisplayDateReceived" To sDisplayDateReceived
    Get ComIntOf Of hoJsonData "ViewCount" To iViewCount
    Get ComStringOf Of hoJsonData "ViewedOn" To sViewedOn
    Get ComIntOf Of hoJsonData "AttachmentCount" To iAttachmentCount
    Get ComIntOf Of hoJsonData "Status" To iStatus
    Get ComIntOf Of hoJsonData "ParentMessageId" To iParentMessageId
    Get ComIntOf Of hoJsonData "DistributionListId" To iDistributionListId
    Get ComStringOf Of hoJsonData "DistributionListName" To sDistributionListName
    Get ComStringOf Of hoJsonData "BodyHistory" To sBodyHistory
    Get ComStringOf Of hoJsonData "ReadReceiptCallbackUrl" To sReadReceiptCallbackUrl
    Get ComBoolOf Of hoJsonData "SendGlobalNotifications" To iSendGlobalNotifications
    Move 0 To i
    Get ComSizeOfArray Of hoJsonData "AttachmentNames" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonData To i
        Get ComIntOf Of hoJsonData "AttachmentNames[i].MessageId" To iMessageId
        Get ComIntOf Of hoJsonData "AttachmentNames[i].Id" To iId
        Get ComStringOf Of hoJsonData "AttachmentNames[i].Name" To sName
        Get ComStringOf Of hoJsonData "AttachmentNames[i].DisplayName" To sDisplayName
        Get ComIntOf Of hoJsonData "AttachmentNames[i].Size" To iSize
        Get ComBoolOf Of hoJsonData "AttachmentNames[i].WasViewed" To iWasViewed
        Get ComStringOf Of hoJsonData "AttachmentNames[i].ViewedOn" To sViewedOn
        Get ComIntOf Of hoJsonData "AttachmentNames[i].ViewCount" To iViewCount
        Get ComStringOf Of hoJsonData "AttachmentNames[i].Location" To sLocation
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJsonData "AllRecipients" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonData To i
        Get ComIntOf Of hoJsonData "AllRecipients[i].Id" To iId
        Get ComStringOf Of hoJsonData "AllRecipients[i].UserName" To sUserName
        Get ComIntOf Of hoJsonData "AllRecipients[i].AccountId" To iAccountId
        Get ComStringOf Of hoJsonData "AllRecipients[i].AccountName" To sAccountName
        Get ComStringOf Of hoJsonData "AllRecipients[i].AccountTitle" To sAccountTitle
        Get ComStringOf Of hoJsonData "AllRecipients[i].FirstName" To sFirstName
        Get ComStringOf Of hoJsonData "AllRecipients[i].LastName" To sLastName
        Get ComStringOf Of hoJsonData "AllRecipients[i].EmailAddress" To sEmailAddress
        Get ComStringOf Of hoJsonData "AllRecipients[i].LastSentOn" To sLastSentOn
        Get ComIntOf Of hoJsonData "AllRecipients[i].SendCount" To iSendCount
        Get ComBoolOf Of hoJsonData "AllRecipients[i].IsFavorite" To iIsFavorite
        Move (i + 1) To i
    Loop



End_Procedure

 

© 2000-2022 Chilkat Software, Inc. All Rights Reserved.