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 3,4,5... 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
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

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
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
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 3,4,5...) Quickbooks Query an Invoice

Demonstrates how to query for invoices matching a SELECT statement via the Quickbooks REST API.

For more information, see https://www.developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/invoice#query-an-invoice

Chilkat Downloads for the Swift Programming Language

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

iOS Objective-C/Swift Libs

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

    // First get our previously obtained OAuth2 access token.
    let jsonToken = CkoJsonObject()!
    var success: Bool = jsonToken.loadFile("qa_data/tokens/qb-access-token.json")

    let rest = CkoRest()!

    var bTls: Bool = true
    var port: Int = 443
    var bAutoReconnect: Bool = true
    var success: Bool = rest.connect("sandbox-quickbooks.api.intuit.com", port: port, tls: bTls, autoReconnect: bAutoReconnect)

    let sbAuth = CkoStringBuilder()!
    sbAuth.append("Bearer ")
    sbAuth.append(jsonToken.string(of: "access_token"))
    rest.authorization = sbAuth.getAsString()

    // --------------------------------------------------------------------------
    // Note: The above REST connection and setup of the AWS credentials
    // can be done once.  After connecting, any number of REST calls can be made.
    // The "auto reconnect" property passed to rest.Connect indicates that if
    // the connection is lost, a REST method call will automatically reconnect
    // if needed.
    // --------------------------------------------------------------------------

    // This is a GET request, so there should be no Content-Type
    // This line of code is just to make sure..
    rest.removeHeader("Content-Type")

    rest.addHeader("Accept", value: "application/json")
    rest.allowHeaderFolding = false

    // Add a SELECT statement 
    rest.addQueryParam("query", value: "select * from Invoice where id = '239'")

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("GET", uriPath: "/v3/company/<realmID>/invoice", sb: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    if respStatusCode >= 400 {
        print("Response Status Code = \(respStatusCode)")
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    // Success is indicated by a 200 response status.
    print("response status code = \(respStatusCode)")

    let json = CkoJsonObject()!
    json.loadSb(sbResponseBody)
    json.emitCompact = false
    print("\(json.emit()!)")

    // Sample output:
    // Use the this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    // {
    //   "QueryResponse": {
    //     "startPosition": 1, 
    //     "totalCount": 1, 
    //     "maxResults": 1, 
    //     "Invoice": [
    //       {
    //         "DocNumber": "1070", 
    //         "SyncToken": "0", 
    //         "domain": "QBO", 
    //         "Balance": 150.0, 
    //         "BillAddr": {
    //           "City": "Bayshore", 
    //           "Line1": "4581 Finch St.", 
    //           "PostalCode": "94326", 
    //           "Lat": "INVALID", 
    //           "Long": "INVALID", 
    //           "CountrySubDivisionCode": "CA", 
    //           "Id": "2"
    //         }, 
    //         "TxnDate": "2015-07-24", 
    //         "TotalAmt": 150.0, 
    //         "CustomerRef": {
    //           "name": "Amy's Bird Sanctuary", 
    //           "value": "1"
    //         }, 
    //         "ShipAddr": {
    //           "City": "Bayshore", 
    //           "Line1": "4581 Finch St.", 
    //           "PostalCode": "94326", 
    //           "Lat": "INVALID", 
    //           "Long": "INVALID", 
    //           "CountrySubDivisionCode": "CA", 
    //           "Id": "109"
    //         }, 
    //         "LinkedTxn": [], 
    //         "DueDate": "2015-08-23", 
    //         "PrintStatus": "NeedToPrint", 
    //         "Deposit": 0, 
    //         "sparse": false, 
    //         "EmailStatus": "NotSet", 
    //         "Line": [
    //           {
    //             "LineNum": 1, 
    //             "Amount": 150.0, 
    //             "SalesItemLineDetail": {
    //               "TaxCodeRef": {
    //                 "value": "NON"
    //               }, 
    //               "ItemRef": {
    //                 "name": "Services", 
    //                 "value": "1"
    //               }
    //             }, 
    //             "Id": "1", 
    //             "DetailType": "SalesItemLineDetail"
    //           }, 
    //           {
    //             "DetailType": "SubTotalLineDetail", 
    //             "Amount": 150.0, 
    //             "SubTotalLineDetail": {}
    //           }
    //         ], 
    //         "ApplyTaxAfterDiscount": false, 
    //         "CustomField": [
    //           {
    //             "DefinitionId": "1", 
    //             "Type": "StringType", 
    //             "Name": "Crew #"
    //           }
    //         ], 
    //         "Id": "239", 
    //         "TxnTaxDetail": {
    //           "TotalTax": 0
    //         }, 
    //         "MetaData": {
    //           "CreateTime": "2015-07-24T10:35:08-07:00", 
    //           "LastUpdatedTime": "2015-07-24T10:35:08-07:00"
    //         }
    //       }
    //     ]
    //   }, 
    //   "time": "2015-07-24T10:38:50.01-07:00"
    // }

    var DocNumber: String?
    var SyncToken: String?
    var domain: String?
    var Balance: String?
    var BillAddrCity: String?
    var BillAddrLine1: String?
    var BillAddrPostalCode: String?
    var BillAddrLat: String?
    var BillAddrLong: String?
    var BillAddrCountrySubDivisionCode: String?
    var BillAddrId: String?
    var TxnDate: String?
    var TotalAmt: String?
    var CustomerRefName: String?
    var CustomerRefValue: String?
    var ShipAddrCity: String?
    var ShipAddrLine1: String?
    var ShipAddrPostalCode: String?
    var ShipAddrLat: String?
    var ShipAddrLong: String?
    var ShipAddrCountrySubDivisionCode: String?
    var ShipAddrId: String?
    var DueDate: String?
    var PrintStatus: String?
    var Deposit: Int
    var sparse: Bool
    var EmailStatus: String?
    var ApplyTaxAfterDiscount: Bool
    var Id: String?
    var TxnTaxDetailTotalTax: Int
    var MetaDataCreateTime: String?
    var MetaDataLastUpdatedTime: String?
    var j: Int
    var count_j: Int
    var LineNum: Int
    var Amount: String?
    var SalesItemLineDetailTaxCodeRefValue: String?
    var SalesItemLineDetailItemRefName: String?
    var SalesItemLineDetailItemRefValue: String?
    var DetailType: String?
    var DefinitionId: String?
    var invType: String?
    var Name: String?

    var QueryResponseStartPosition: Int = json.int(of: "QueryResponse.startPosition").intValue
    var QueryResponseTotalCount: Int = json.int(of: "QueryResponse.totalCount").intValue
    var QueryResponseMaxResults: Int = json.int(of: "QueryResponse.maxResults").intValue
    var time: String? = json.string(of: "time")
    var i: Int = 0
    var count_i: Int = json.size(ofArray: "QueryResponse.Invoice").intValue
    while i < count_i {
        json.i = i
        DocNumber = json.string(of: "QueryResponse.Invoice[i].DocNumber")
        SyncToken = json.string(of: "QueryResponse.Invoice[i].SyncToken")
        domain = json.string(of: "QueryResponse.Invoice[i].domain")
        Balance = json.string(of: "QueryResponse.Invoice[i].Balance")
        BillAddrCity = json.string(of: "QueryResponse.Invoice[i].BillAddr.City")
        BillAddrLine1 = json.string(of: "QueryResponse.Invoice[i].BillAddr.Line1")
        BillAddrPostalCode = json.string(of: "QueryResponse.Invoice[i].BillAddr.PostalCode")
        BillAddrLat = json.string(of: "QueryResponse.Invoice[i].BillAddr.Lat")
        BillAddrLong = json.string(of: "QueryResponse.Invoice[i].BillAddr.Long")
        BillAddrCountrySubDivisionCode = json.string(of: "QueryResponse.Invoice[i].BillAddr.CountrySubDivisionCode")
        BillAddrId = json.string(of: "QueryResponse.Invoice[i].BillAddr.Id")
        TxnDate = json.string(of: "QueryResponse.Invoice[i].TxnDate")
        TotalAmt = json.string(of: "QueryResponse.Invoice[i].TotalAmt")
        CustomerRefName = json.string(of: "QueryResponse.Invoice[i].CustomerRef.name")
        CustomerRefValue = json.string(of: "QueryResponse.Invoice[i].CustomerRef.value")
        ShipAddrCity = json.string(of: "QueryResponse.Invoice[i].ShipAddr.City")
        ShipAddrLine1 = json.string(of: "QueryResponse.Invoice[i].ShipAddr.Line1")
        ShipAddrPostalCode = json.string(of: "QueryResponse.Invoice[i].ShipAddr.PostalCode")
        ShipAddrLat = json.string(of: "QueryResponse.Invoice[i].ShipAddr.Lat")
        ShipAddrLong = json.string(of: "QueryResponse.Invoice[i].ShipAddr.Long")
        ShipAddrCountrySubDivisionCode = json.string(of: "QueryResponse.Invoice[i].ShipAddr.CountrySubDivisionCode")
        ShipAddrId = json.string(of: "QueryResponse.Invoice[i].ShipAddr.Id")
        DueDate = json.string(of: "QueryResponse.Invoice[i].DueDate")
        PrintStatus = json.string(of: "QueryResponse.Invoice[i].PrintStatus")
        Deposit = json.int(of: "QueryResponse.Invoice[i].Deposit").intValue
        sparse = json.bool(of: "QueryResponse.Invoice[i].sparse")
        EmailStatus = json.string(of: "QueryResponse.Invoice[i].EmailStatus")
        ApplyTaxAfterDiscount = json.bool(of: "QueryResponse.Invoice[i].ApplyTaxAfterDiscount")
        Id = json.string(of: "QueryResponse.Invoice[i].Id")
        TxnTaxDetailTotalTax = json.int(of: "QueryResponse.Invoice[i].TxnTaxDetail.TotalTax").intValue
        MetaDataCreateTime = json.string(of: "QueryResponse.Invoice[i].MetaData.CreateTime")
        MetaDataLastUpdatedTime = json.string(of: "QueryResponse.Invoice[i].MetaData.LastUpdatedTime")
        j = 0
        count_j = json.size(ofArray: "QueryResponse.Invoice[i].LinkedTxn").intValue
        while j < count_j {
            json.j = j
            j = j + 1
        }

        j = 0
        count_j = json.size(ofArray: "QueryResponse.Invoice[i].Line").intValue
        while j < count_j {
            json.j = j
            LineNum = json.int(of: "QueryResponse.Invoice[i].Line[j].LineNum").intValue
            Amount = json.string(of: "QueryResponse.Invoice[i].Line[j].Amount")
            SalesItemLineDetailTaxCodeRefValue = json.string(of: "QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.TaxCodeRef.value")
            SalesItemLineDetailItemRefName = json.string(of: "QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.ItemRef.name")
            SalesItemLineDetailItemRefValue = json.string(of: "QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.ItemRef.value")
            Id = json.string(of: "QueryResponse.Invoice[i].Line[j].Id")
            DetailType = json.string(of: "QueryResponse.Invoice[i].Line[j].DetailType")
            j = j + 1
        }

        j = 0
        count_j = json.size(ofArray: "QueryResponse.Invoice[i].CustomField").intValue
        while j < count_j {
            json.j = j
            DefinitionId = json.string(of: "QueryResponse.Invoice[i].CustomField[j].DefinitionId")
            invType = json.string(of: "QueryResponse.Invoice[i].CustomField[j].Type")
            Name = json.string(of: "QueryResponse.Invoice[i].CustomField[j].Name")
            j = j + 1
        }

        i = i + 1
    }


}

 

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