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

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

 

 

 

(DataFlex) Xero Upload Attachment

Upload an attachment. (POST an attachment).

Note: Requires Chilkat v9.5.0.64 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    String sEndPoint
    String sReceiptID
    String sFilename
    Handle hoSbPath
    Integer iNumReplaced
    Variant vJpgData
    Handle hoJpgData
    Variant vJpgDataFromWeb
    Handle hoJpgDataFromWeb
    Handle hoHttp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    String sTemp1
    Integer iTemp1

    // Note: Requires Chilkat v9.5.0.64 or greater.

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

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    // Before sending REST API calls, the REST object needs to be
    // initialized for OAuth1.
    // See Xero 2-Legged OAuth1 Setup for sample code.

    // Assuming the REST object's OAuth1 authenticator is setup, and the initial
    // connection was made, we may now send REST HTTP requests..

    // --------------------------------------------------------------
    // This example will upload an image attachment to a receipt.

    Move "Receipts" To sEndPoint
    Move "c4f40e59-c390-0001-caff-ce731c707d00" To sReceiptID
    // This JPG image can be downloaded from https://www.chilkatsoft.com/syncedImages/penguins.jpg
    Move "penguins.jpg" To sFilename

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbPath
    If (Not(IsComObjectCreated(hoSbPath))) Begin
        Send CreateComObject of hoSbPath
    End
    Get ComAppend Of hoSbPath "/api.xro/2.0/{Endpoint}/{Guid}/Attachments/{Filename}" To iSuccess
    Get ComReplace Of hoSbPath "{Endpoint}" sEndPoint To iNumReplaced
    Get ComReplace Of hoSbPath "{Guid}" sReceiptID To iNumReplaced
    Get ComReplace Of hoSbPath "{Filename}" sFilename To iNumReplaced

    Get ComAddHeader Of hoRest "Content-Type" "image/jpeg" To iSuccess

    // Load the JPG image from a file.
    Get Create (RefClass(cComChilkatBinData)) To hoJpgData
    If (Not(IsComObjectCreated(hoJpgData))) Begin
        Send CreateComObject of hoJpgData
    End
    Get ComLoadFile Of hoJpgData "qa_data/jpg/penguins.jpg" To iSuccess

    // We could alternatively get it from a URL like this:
    Get Create (RefClass(cComChilkatBinData)) To hoJpgDataFromWeb
    If (Not(IsComObjectCreated(hoJpgDataFromWeb))) Begin
        Send CreateComObject of hoJpgDataFromWeb
    End
    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Get pvComObject of hoJpgDataFromWeb to vJpgDataFromWeb
    Get ComQuickGetBd Of hoHttp "https://www.chilkatsoft.com/syncedImages/penguins.jpg" vJpgDataFromWeb To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Upload with a POST
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get ComGetAsString Of hoSbPath To sTemp1
    Get pvComObject of hoJpgData to vJpgData
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestBd Of hoRest "POST" sTemp1 vJpgData vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // A 200 response is expected for actual success.
    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComGetAsString Of hoSbResponseBody To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Examine the XML response
    Get ComGetAsString Of hoSbResponseBody To sTemp1
    Showln sTemp1

    // A successful response looks like this:

    // 	<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    // 	  <Id>d82568cd-d222-49e6-b713-880b6edb0606</Id>
    // 	  <Status>OK</Status>
    // 	  <ProviderName>ChilkatPrivate</ProviderName>
    // 	  <DateTimeUTC>2016-11-11T14:17:49.5922609Z</DateTimeUTC>
    // 	  <Attachments>
    // 	    <Attachment>
    // 	      <AttachmentID>0edcddc8-325f-40c7-b950-8c71f14afc7c</AttachmentID>
    // 	      <FileName>penguins.jpg</FileName>
    // 	      <Url>http://api.xero.com/api.xro/2.0/Receipts/c4f40e59-c390-0001-caff-ce731c707d00/Attachments/penguins.jpg</Url>
    // 	      <MimeType>image/jpg</MimeType>
    // 	      <ContentLength>777835</ContentLength>
    // 	    </Attachment>
    // 	  </Attachments>
    // 	</Response>


End_Procedure

 

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