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
(PowerBuilder) 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
integer li_rc oleobject loo_JsonToken integer li_Success oleobject loo_Rest integer li_BTls integer li_Port integer li_BAutoReconnect integer li_Success oleobject loo_SbAuth oleobject loo_JsonReq oleobject loo_SbRequestBody oleobject loo_SbResponseBody integer li_RespStatusCode oleobject loo_JsonResponse string ls_CustomerDomain string ls_CustomerPrimaryEmailAddrAddress string ls_CustomerDisplayName string ls_CustomerCurrencyRefName string ls_CustomerCurrencyRefValue string ls_CustomerDefaultTaxCodeRefValue string ls_CustomerPreferredDeliveryMethod string ls_CustomerGivenName string ls_CustomerFullyQualifiedName integer li_CustomerBillWithParent string ls_CustomerTitle integer li_CustomerJob integer li_CustomerBalanceWithJobs string ls_CustomerPrimaryPhoneFreeFormNumber integer li_CustomerTaxable string ls_CustomerMetaDataCreateTime string ls_CustomerMetaDataLastUpdatedTime string ls_CustomerBillAddrCity string ls_CustomerBillAddrCountry string ls_CustomerBillAddrLine1 string ls_CustomerBillAddrPostalCode string ls_CustomerBillAddrCountrySubDivisionCode string ls_CustomerBillAddrId string ls_CustomerMiddleName string ls_CustomerNotes integer li_CustomerActive integer li_CustomerBalance string ls_CustomerSyncToken string ls_CustomerSuffix string ls_CustomerCompanyName string ls_CustomerFamilyName string ls_CustomerPrintOnCheckName integer li_CustomerSparse string ls_CustomerId string ls_Time // 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. loo_JsonToken = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject") if li_rc < 0 then destroy loo_JsonToken MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_JsonToken.LoadFile("qa_data/tokens/qb-access-token.json") loo_Rest = create oleobject // Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0 li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest") // Connect to the REST server. li_BTls = 1 li_Port = 443 li_BAutoReconnect = 1 li_Success = loo_Rest.Connect("sandbox-quickbooks.api.intuit.com",li_Port,li_BTls,li_BAutoReconnect) loo_SbAuth = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbAuth.ConnectToNewObject("Chilkat.StringBuilder") loo_SbAuth.Append("Bearer ") loo_SbAuth.Append(loo_JsonToken.StringOf("access_token")) loo_Rest.Authorization = loo_SbAuth.GetAsString() // -------------------------------------------------------------------------- // 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 loo_JsonReq = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonReq.ConnectToNewObject("Chilkat.JsonObject") loo_JsonReq.UpdateString("FullyQualifiedName","King Groceries") loo_JsonReq.UpdateString("PrimaryEmailAddr.Address","jdrew@myemail.com") loo_JsonReq.UpdateString("DisplayName","King's Groceries") loo_JsonReq.UpdateString("Suffix","Jr") loo_JsonReq.UpdateString("Title","Mr") loo_JsonReq.UpdateString("MiddleName","B") loo_JsonReq.UpdateString("Notes","Here are other details.") loo_JsonReq.UpdateString("FamilyName","King") loo_JsonReq.UpdateString("PrimaryPhone.FreeFormNumber","(555) 555-5555") loo_JsonReq.UpdateString("CompanyName","King Groceries") loo_JsonReq.UpdateString("BillAddr.CountrySubDivisionCode","CA") loo_JsonReq.UpdateString("BillAddr.City","Mountain View") loo_JsonReq.UpdateString("BillAddr.PostalCode","94042") loo_JsonReq.UpdateString("BillAddr.Line1","123 Main Street") loo_JsonReq.UpdateString("BillAddr.Country","USA") loo_JsonReq.UpdateString("GivenName","James") loo_SbRequestBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder") loo_JsonReq.EmitSb(loo_SbRequestBody) loo_Rest.AddHeader("Content-Type","application/json") loo_Rest.AddHeader("Accept","application/json") loo_Rest.AllowHeaderFolding = 0 loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") li_Success = loo_Rest.FullRequestSb("POST","/v3/company/<realmID>/customer",loo_SbRequestBody,loo_SbResponseBody) if li_Success <> 1 then Write-Debug loo_Rest.LastErrorText destroy loo_JsonToken destroy loo_Rest destroy loo_SbAuth destroy loo_JsonReq destroy loo_SbRequestBody destroy loo_SbResponseBody return end if li_RespStatusCode = loo_Rest.ResponseStatusCode // Success is indicated by a 200 response status code. Write-Debug "response status code = " + string(li_RespStatusCode) loo_JsonResponse = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat.JsonObject") loo_JsonResponse.LoadSb(loo_SbResponseBody) loo_JsonResponse.EmitCompact = 0 Write-Debug loo_JsonResponse.Emit() if loo_Rest.ResponseStatusCode <> 200 then Write-Debug "Failed." destroy loo_JsonToken destroy loo_Rest destroy loo_SbAuth destroy loo_JsonReq destroy loo_SbRequestBody destroy loo_SbResponseBody destroy loo_JsonResponse return end if // 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" // } // ls_CustomerDomain = loo_JsonResponse.StringOf("Customer.domain") ls_CustomerPrimaryEmailAddrAddress = loo_JsonResponse.StringOf("Customer.PrimaryEmailAddr.Address") ls_CustomerDisplayName = loo_JsonResponse.StringOf("Customer.DisplayName") ls_CustomerCurrencyRefName = loo_JsonResponse.StringOf("Customer.CurrencyRef.name") ls_CustomerCurrencyRefValue = loo_JsonResponse.StringOf("Customer.CurrencyRef.value") ls_CustomerDefaultTaxCodeRefValue = loo_JsonResponse.StringOf("Customer.DefaultTaxCodeRef.value") ls_CustomerPreferredDeliveryMethod = loo_JsonResponse.StringOf("Customer.PreferredDeliveryMethod") ls_CustomerGivenName = loo_JsonResponse.StringOf("Customer.GivenName") ls_CustomerFullyQualifiedName = loo_JsonResponse.StringOf("Customer.FullyQualifiedName") li_CustomerBillWithParent = loo_JsonResponse.BoolOf("Customer.BillWithParent") ls_CustomerTitle = loo_JsonResponse.StringOf("Customer.Title") li_CustomerJob = loo_JsonResponse.BoolOf("Customer.Job") li_CustomerBalanceWithJobs = loo_JsonResponse.IntOf("Customer.BalanceWithJobs") ls_CustomerPrimaryPhoneFreeFormNumber = loo_JsonResponse.StringOf("Customer.PrimaryPhone.FreeFormNumber") li_CustomerTaxable = loo_JsonResponse.BoolOf("Customer.Taxable") ls_CustomerMetaDataCreateTime = loo_JsonResponse.StringOf("Customer.MetaData.CreateTime") ls_CustomerMetaDataLastUpdatedTime = loo_JsonResponse.StringOf("Customer.MetaData.LastUpdatedTime") ls_CustomerBillAddrCity = loo_JsonResponse.StringOf("Customer.BillAddr.City") ls_CustomerBillAddrCountry = loo_JsonResponse.StringOf("Customer.BillAddr.Country") ls_CustomerBillAddrLine1 = loo_JsonResponse.StringOf("Customer.BillAddr.Line1") ls_CustomerBillAddrPostalCode = loo_JsonResponse.StringOf("Customer.BillAddr.PostalCode") ls_CustomerBillAddrCountrySubDivisionCode = loo_JsonResponse.StringOf("Customer.BillAddr.CountrySubDivisionCode") ls_CustomerBillAddrId = loo_JsonResponse.StringOf("Customer.BillAddr.Id") ls_CustomerMiddleName = loo_JsonResponse.StringOf("Customer.MiddleName") ls_CustomerNotes = loo_JsonResponse.StringOf("Customer.Notes") li_CustomerActive = loo_JsonResponse.BoolOf("Customer.Active") li_CustomerBalance = loo_JsonResponse.IntOf("Customer.Balance") ls_CustomerSyncToken = loo_JsonResponse.StringOf("Customer.SyncToken") ls_CustomerSuffix = loo_JsonResponse.StringOf("Customer.Suffix") ls_CustomerCompanyName = loo_JsonResponse.StringOf("Customer.CompanyName") ls_CustomerFamilyName = loo_JsonResponse.StringOf("Customer.FamilyName") ls_CustomerPrintOnCheckName = loo_JsonResponse.StringOf("Customer.PrintOnCheckName") li_CustomerSparse = loo_JsonResponse.BoolOf("Customer.sparse") ls_CustomerId = loo_JsonResponse.StringOf("Customer.Id") ls_Time = loo_JsonResponse.StringOf("time") destroy loo_JsonToken destroy loo_Rest destroy loo_SbAuth destroy loo_JsonReq destroy loo_SbRequestBody destroy loo_SbResponseBody destroy loo_JsonResponse |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.