Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Quickbooks Create a New CustomerDemonstrates how to create a new customer via the Quickbooks REST API. For more information, see https://www.developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/customer#create-a-customer
Use ChilkatAx-win32.pkg Procedure Test Handle hoJsonToken Boolean iSuccess Handle hoRest Boolean iBTls Integer iPort Boolean iBAutoReconnect Boolean iSuccess Handle hoSbAuth Handle hoJsonReq Variant vSbRequestBody Handle hoSbRequestBody Variant vSbResponseBody Handle hoSbResponseBody Integer iRespStatusCode Handle hoJsonResponse String sCustomerDomain String sCustomerPrimaryEmailAddrAddress String sCustomerDisplayName String sCustomerCurrencyRefName String sCustomerCurrencyRefValue String sCustomerDefaultTaxCodeRefValue String sCustomerPreferredDeliveryMethod String sCustomerGivenName String sCustomerFullyQualifiedName Boolean iCustomerBillWithParent String sCustomerTitle Boolean iCustomerJob Integer iCustomerBalanceWithJobs String sCustomerPrimaryPhoneFreeFormNumber Boolean iCustomerTaxable String sCustomerMetaDataCreateTime String sCustomerMetaDataLastUpdatedTime String sCustomerBillAddrCity String sCustomerBillAddrCountry String sCustomerBillAddrLine1 String sCustomerBillAddrPostalCode String sCustomerBillAddrCountrySubDivisionCode String sCustomerBillAddrId String sCustomerMiddleName String sCustomerNotes Boolean iCustomerActive Integer iCustomerBalance String sCustomerSyncToken String sCustomerSuffix String sCustomerCompanyName String sCustomerFamilyName String sCustomerPrintOnCheckName Boolean iCustomerSparse String sCustomerId String sTime String sTemp1 Integer iTemp1 // 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. Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken If (Not(IsComObjectCreated(hoJsonToken))) Begin Send CreateComObject of hoJsonToken End Get ComLoadFile Of hoJsonToken "qa_data/tokens/qb-access-token.json" To iSuccess Get Create (RefClass(cComChilkatRest)) To hoRest If (Not(IsComObjectCreated(hoRest))) Begin Send CreateComObject of hoRest End // Connect to the REST server. Move True To iBTls Move 443 To iPort Move True To iBAutoReconnect Get ComConnect Of hoRest "sandbox-quickbooks.api.intuit.com" iPort iBTls iBAutoReconnect To iSuccess Get Create (RefClass(cComChilkatStringBuilder)) To hoSbAuth If (Not(IsComObjectCreated(hoSbAuth))) Begin Send CreateComObject of hoSbAuth End Get ComAppend Of hoSbAuth "Bearer " To iSuccess Get ComStringOf Of hoJsonToken "access_token" To sTemp1 Get ComAppend Of hoSbAuth sTemp1 To iSuccess Get ComGetAsString Of hoSbAuth To sTemp1 Set ComAuthorization Of hoRest To sTemp1 // -------------------------------------------------------------------------- // Note: The above code to setup the initial REST connection // can be done once. After connecting, any number of REST calls can be made. // If the connection is lost, the next REST method call will automatically // reconnect if needed. // -------------------------------------------------------------------------- // Create the following JSON: // { // "FullyQualifiedName": "King Groceries", // "PrimaryEmailAddr": { // "Address": "jdrew@myemail.com" // }, // "DisplayName": "King's Groceries", // "Suffix": "Jr", // "Title": "Mr", // "MiddleName": "B", // "Notes": "Here are other details.", // "FamilyName": "King", // "PrimaryPhone": { // "FreeFormNumber": "(555) 555-5555" // }, // "CompanyName": "King Groceries", // "BillAddr": { // "CountrySubDivisionCode": "CA", // "City": "Mountain View", // "PostalCode": "94042", // "Line1": "123 Main Street", // "Country": "USA" // }, // "GivenName": "James" // } // // Use the this online tool to generate the code from sample JSON: // Generate Code to Create JSON Get Create (RefClass(cComChilkatJsonObject)) To hoJsonReq If (Not(IsComObjectCreated(hoJsonReq))) Begin Send CreateComObject of hoJsonReq End Get ComUpdateString Of hoJsonReq "FullyQualifiedName" "King Groceries" To iSuccess Get ComUpdateString Of hoJsonReq "PrimaryEmailAddr.Address" "jdrew@myemail.com" To iSuccess Get ComUpdateString Of hoJsonReq "DisplayName" "King's Groceries" To iSuccess Get ComUpdateString Of hoJsonReq "Suffix" "Jr" To iSuccess Get ComUpdateString Of hoJsonReq "Title" "Mr" To iSuccess Get ComUpdateString Of hoJsonReq "MiddleName" "B" To iSuccess Get ComUpdateString Of hoJsonReq "Notes" "Here are other details." To iSuccess Get ComUpdateString Of hoJsonReq "FamilyName" "King" To iSuccess Get ComUpdateString Of hoJsonReq "PrimaryPhone.FreeFormNumber" "(555) 555-5555" To iSuccess Get ComUpdateString Of hoJsonReq "CompanyName" "King Groceries" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.CountrySubDivisionCode" "CA" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.City" "Mountain View" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.PostalCode" "94042" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.Line1" "123 Main Street" To iSuccess Get ComUpdateString Of hoJsonReq "BillAddr.Country" "USA" To iSuccess Get ComUpdateString Of hoJsonReq "GivenName" "James" To iSuccess Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody If (Not(IsComObjectCreated(hoSbRequestBody))) Begin Send CreateComObject of hoSbRequestBody End Get pvComObject of hoSbRequestBody to vSbRequestBody Get ComEmitSb Of hoJsonReq vSbRequestBody To iSuccess Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess Get ComAddHeader Of hoRest "Accept" "application/json" To iSuccess Set ComAllowHeaderFolding Of hoRest To False Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody If (Not(IsComObjectCreated(hoSbResponseBody))) Begin Send CreateComObject of hoSbResponseBody End Get pvComObject of hoSbRequestBody to vSbRequestBody Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComFullRequestSb Of hoRest "POST" "/v3/company/<realmID>/customer" vSbRequestBody vSbResponseBody To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoRest To sTemp1 Showln sTemp1 Procedure_Return End Get ComResponseStatusCode Of hoRest To iRespStatusCode // Success is indicated by a 200 response status code. Showln "response status code = " iRespStatusCode Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse If (Not(IsComObjectCreated(hoJsonResponse))) Begin Send CreateComObject of hoJsonResponse End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess Set ComEmitCompact Of hoJsonResponse To False Get ComEmit Of hoJsonResponse To sTemp1 Showln sTemp1 Get ComResponseStatusCode Of hoRest To iTemp1 If (iTemp1 <> 200) Begin Showln "Failed." Procedure_Return End // Sample output... // (See the parsing code below..) // // Use the this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // { // "Customer": { // "domain": "QBO", // "PrimaryEmailAddr": { // "Address": "jdrew@myemail.com" // }, // "DisplayName": "King's Groceries", // "CurrencyRef": { // "name": "United States Dollar", // "value": "USD" // }, // "DefaultTaxCodeRef": { // "value": "2" // }, // "PreferredDeliveryMethod": "Print", // "GivenName": "James", // "FullyQualifiedName": "King's Groceries", // "BillWithParent": false, // "Title": "Mr", // "Job": false, // "BalanceWithJobs": 0, // "PrimaryPhone": { // "FreeFormNumber": "(555) 555-5555" // }, // "Taxable": true, // "MetaData": { // "CreateTime": "2015-07-23T10:58:12-07:00", // "LastUpdatedTime": "2015-07-23T10:58:12-07:00" // }, // "BillAddr": { // "City": "Mountain View", // "Country": "USA", // "Line1": "123 Main Street", // "PostalCode": "94042", // "CountrySubDivisionCode": "CA", // "Id": "112" // }, // "MiddleName": "B", // "Notes": "Here are other details.", // "Active": true, // "Balance": 0, // "SyncToken": "0", // "Suffix": "Jr", // "CompanyName": "King Groceries", // "FamilyName": "King", // "PrintOnCheckName": "King Groceries", // "sparse": false, // "Id": "67" // }, // "time": "2015-07-23T10:58:12.099-07:00" // } // Get ComStringOf Of hoJsonResponse "Customer.domain" To sCustomerDomain Get ComStringOf Of hoJsonResponse "Customer.PrimaryEmailAddr.Address" To sCustomerPrimaryEmailAddrAddress Get ComStringOf Of hoJsonResponse "Customer.DisplayName" To sCustomerDisplayName Get ComStringOf Of hoJsonResponse "Customer.CurrencyRef.name" To sCustomerCurrencyRefName Get ComStringOf Of hoJsonResponse "Customer.CurrencyRef.value" To sCustomerCurrencyRefValue Get ComStringOf Of hoJsonResponse "Customer.DefaultTaxCodeRef.value" To sCustomerDefaultTaxCodeRefValue Get ComStringOf Of hoJsonResponse "Customer.PreferredDeliveryMethod" To sCustomerPreferredDeliveryMethod Get ComStringOf Of hoJsonResponse "Customer.GivenName" To sCustomerGivenName Get ComStringOf Of hoJsonResponse "Customer.FullyQualifiedName" To sCustomerFullyQualifiedName Get ComBoolOf Of hoJsonResponse "Customer.BillWithParent" To iCustomerBillWithParent Get ComStringOf Of hoJsonResponse "Customer.Title" To sCustomerTitle Get ComBoolOf Of hoJsonResponse "Customer.Job" To iCustomerJob Get ComIntOf Of hoJsonResponse "Customer.BalanceWithJobs" To iCustomerBalanceWithJobs Get ComStringOf Of hoJsonResponse "Customer.PrimaryPhone.FreeFormNumber" To sCustomerPrimaryPhoneFreeFormNumber Get ComBoolOf Of hoJsonResponse "Customer.Taxable" To iCustomerTaxable Get ComStringOf Of hoJsonResponse "Customer.MetaData.CreateTime" To sCustomerMetaDataCreateTime Get ComStringOf Of hoJsonResponse "Customer.MetaData.LastUpdatedTime" To sCustomerMetaDataLastUpdatedTime Get ComStringOf Of hoJsonResponse "Customer.BillAddr.City" To sCustomerBillAddrCity Get ComStringOf Of hoJsonResponse "Customer.BillAddr.Country" To sCustomerBillAddrCountry Get ComStringOf Of hoJsonResponse "Customer.BillAddr.Line1" To sCustomerBillAddrLine1 Get ComStringOf Of hoJsonResponse "Customer.BillAddr.PostalCode" To sCustomerBillAddrPostalCode Get ComStringOf Of hoJsonResponse "Customer.BillAddr.CountrySubDivisionCode" To sCustomerBillAddrCountrySubDivisionCode Get ComStringOf Of hoJsonResponse "Customer.BillAddr.Id" To sCustomerBillAddrId Get ComStringOf Of hoJsonResponse "Customer.MiddleName" To sCustomerMiddleName Get ComStringOf Of hoJsonResponse "Customer.Notes" To sCustomerNotes Get ComBoolOf Of hoJsonResponse "Customer.Active" To iCustomerActive Get ComIntOf Of hoJsonResponse "Customer.Balance" To iCustomerBalance Get ComStringOf Of hoJsonResponse "Customer.SyncToken" To sCustomerSyncToken Get ComStringOf Of hoJsonResponse "Customer.Suffix" To sCustomerSuffix Get ComStringOf Of hoJsonResponse "Customer.CompanyName" To sCustomerCompanyName Get ComStringOf Of hoJsonResponse "Customer.FamilyName" To sCustomerFamilyName Get ComStringOf Of hoJsonResponse "Customer.PrintOnCheckName" To sCustomerPrintOnCheckName Get ComBoolOf Of hoJsonResponse "Customer.sparse" To iCustomerSparse Get ComStringOf Of hoJsonResponse "Customer.Id" To sCustomerId Get ComStringOf Of hoJsonResponse "time" To sTime End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.