Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Swift 2 Web API Examples

Primary Categories

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

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
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 API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Swift 2) MedTunnel: Send Message Text Only

See more MedTunnel Examples

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

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

Chilkat Downloads for the Swift Programming Language

MAC OS X (Cocoa) Objective-C/Swift Libs

iOS Objective-C/Swift Libs

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

    let http = CkoHttp()
    var success: Bool

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

    let req = CkoHttpRequest()
    req.HttpVerb = "POST"
    req.Path = "/MedTunnelMsg/api/Message/SendMessage"
    req.ContentType = "multipart/form-data"
    req.AddParam("ApplicationId", value: "yourApplicationId")
    req.AddParam("LocationId", value: "yourLocationId")
    req.AddParam("MedTunnelId", value: "yourMedTunnelId")
    req.AddParam("MedTunnelPassword", value: "yourMedTunnelPassword")
    req.AddParam("To", value: "recipientsMedTunnelId")
    req.AddParam("Body", value: "Test")

    var resp: CkoHttpResponse? = http.SynchronousRequest("server.medtunnel.com", port: 443, ssl: true, req: req)
    if http.LastMethodSuccess == false {
        print("\(http.LastErrorText)")
        return
    }

    let sbResponseBody = CkoStringBuilder()
    resp!.GetBodySb(sbResponseBody)
    let jResp = CkoJsonObject()
    jResp.LoadSb(sbResponseBody)
    jResp.EmitCompact = false

    print("Response Body:")
    print("\(jResp.Emit())")

    var respStatusCode: Int = resp!.StatusCode.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(resp!.Header)")
        print("Failed.")
        resp = nil
        return
    }

    resp = nil

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

    var ReturnCode: Int = jResp.IntOf("ReturnCode").intValue
    var ReturnCodeText: String? = jResp.StringOf("ReturnCodeText")
    var Data: String? = jResp.StringOf("Data")

    // Load the Data into another JSON object and parse..
    let jsonData = CkoJsonObject()
    jsonData.Load(Data)
    jsonData.EmitCompact = false
    print("\(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
    // }
    // 

    var UserName: String?
    var AccountId: Int
    var AccountName: String?
    var AccountTitle: String?
    var FirstName: String?
    var LastName: String?
    var LastSentOn: String?
    var SendCount: Int
    var IsFavorite: Bool

    var Id: Int = jsonData.IntOf("Id").intValue
    var FromUserId: Int = jsonData.IntOf("FromUserId").intValue
    var FromMailBoxId: Int = jsonData.IntOf("FromMailBoxId").intValue
    var FromUserType: Int = jsonData.IntOf("FromUserType").intValue
    var FromUserName: String? = jsonData.StringOf("FromUserName")
    var FromUserFullName: String? = jsonData.StringOf("FromUserFullName")
    var FromUserAccountName: String? = jsonData.StringOf("FromUserAccountName")
    var FromUserAccountTitle: String? = jsonData.StringOf("FromUserAccountTitle")
    var ToUserId: Int = jsonData.IntOf("ToUserId").intValue
    var ToUserType: Int = jsonData.IntOf("ToUserType").intValue
    var ToUserMailboxId: String? = jsonData.StringOf("ToUserMailboxId")
    var ToUserName: String? = jsonData.StringOf("ToUserName")
    var ToUserFullName: String? = jsonData.StringOf("ToUserFullName")
    var EmailAddress: String? = jsonData.StringOf("EmailAddress")
    var Password: String? = jsonData.StringOf("Password")
    var Subject: String? = jsonData.StringOf("Subject")
    var PatientMedTunnelId: String? = jsonData.StringOf("PatientMedTunnelId")
    var Body: String? = jsonData.StringOf("Body")
    var DateReceived: String? = jsonData.StringOf("DateReceived")
    var DisplayDateReceived: String? = jsonData.StringOf("DisplayDateReceived")
    var ViewCount: Int = jsonData.IntOf("ViewCount").intValue
    var ViewedOn: String? = jsonData.StringOf("ViewedOn")
    var AttachmentCount: Int = jsonData.IntOf("AttachmentCount").intValue
    var Status: Int = jsonData.IntOf("Status").intValue
    var ParentMessageId: Int = jsonData.IntOf("ParentMessageId").intValue
    var DistributionListId: Int = jsonData.IntOf("DistributionListId").intValue
    var DistributionListName: String? = jsonData.StringOf("DistributionListName")
    var BodyHistory: String? = jsonData.StringOf("BodyHistory")
    var ReadReceiptCallbackUrl: String? = jsonData.StringOf("ReadReceiptCallbackUrl")
    var SendGlobalNotifications: Bool = jsonData.BoolOf("SendGlobalNotifications")
    var i: Int = 0
    var count_i: Int = jsonData.SizeOfArray("AttachmentNames").intValue
    while i < count_i {
        jsonData.I = i
        i = i + 1
    }

    i = 0
    count_i = jsonData.SizeOfArray("AllRecipients").intValue
    while i < count_i {
        jsonData.I = i
        Id = jsonData.IntOf("AllRecipients[i].Id").intValue
        UserName = jsonData.StringOf("AllRecipients[i].UserName")
        AccountId = jsonData.IntOf("AllRecipients[i].AccountId").intValue
        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").intValue
        IsFavorite = jsonData.BoolOf("AllRecipients[i].IsFavorite")
        i = i + 1
    }


}

 

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