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
(Lianja) 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
// 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. loJsonToken = createobject("CkJsonObject") llSuccess = loJsonToken.LoadFile("qa_data/tokens/qb-access-token.json") loRest = createobject("CkRest") // Connect to the REST server. llBTls = .T. lnPort = 443 llBAutoReconnect = .T. llSuccess = loRest.Connect("sandbox-quickbooks.api.intuit.com",lnPort,llBTls,llBAutoReconnect) loSbAuth = createobject("CkStringBuilder") loSbAuth.Append("Bearer ") loSbAuth.Append(loJsonToken.StringOf("access_token")) loRest.Authorization = loSbAuth.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 loJsonReq = createobject("CkJsonObject") loJsonReq.UpdateString("FullyQualifiedName","King Groceries") loJsonReq.UpdateString("PrimaryEmailAddr.Address","jdrew@myemail.com") loJsonReq.UpdateString("DisplayName","King's Groceries") loJsonReq.UpdateString("Suffix","Jr") loJsonReq.UpdateString("Title","Mr") loJsonReq.UpdateString("MiddleName","B") loJsonReq.UpdateString("Notes","Here are other details.") loJsonReq.UpdateString("FamilyName","King") loJsonReq.UpdateString("PrimaryPhone.FreeFormNumber","(555) 555-5555") loJsonReq.UpdateString("CompanyName","King Groceries") loJsonReq.UpdateString("BillAddr.CountrySubDivisionCode","CA") loJsonReq.UpdateString("BillAddr.City","Mountain View") loJsonReq.UpdateString("BillAddr.PostalCode","94042") loJsonReq.UpdateString("BillAddr.Line1","123 Main Street") loJsonReq.UpdateString("BillAddr.Country","USA") loJsonReq.UpdateString("GivenName","James") loSbRequestBody = createobject("CkStringBuilder") loJsonReq.EmitSb(loSbRequestBody) loRest.AddHeader("Content-Type","application/json") loRest.AddHeader("Accept","application/json") loRest.AllowHeaderFolding = .F. loSbResponseBody = createobject("CkStringBuilder") llSuccess = loRest.FullRequestSb("POST","/v3/company/<realmID>/customer",loSbRequestBody,loSbResponseBody) if (llSuccess <> .T.) then ? loRest.LastErrorText release loJsonToken release loRest release loSbAuth release loJsonReq release loSbRequestBody release loSbResponseBody return endif lnRespStatusCode = loRest.ResponseStatusCode // Success is indicated by a 200 response status code. ? "response status code = " + str(lnRespStatusCode) loJsonResponse = createobject("CkJsonObject") loJsonResponse.LoadSb(loSbResponseBody) loJsonResponse.EmitCompact = .F. ? loJsonResponse.Emit() if (loRest.ResponseStatusCode <> 200) then ? "Failed." release loJsonToken release loRest release loSbAuth release loJsonReq release loSbRequestBody release loSbResponseBody release loJsonResponse return endif // 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" // } // lcCustomerDomain = loJsonResponse.StringOf("Customer.domain") lcCustomerPrimaryEmailAddrAddress = loJsonResponse.StringOf("Customer.PrimaryEmailAddr.Address") lcCustomerDisplayName = loJsonResponse.StringOf("Customer.DisplayName") lcCustomerCurrencyRefName = loJsonResponse.StringOf("Customer.CurrencyRef.name") lcCustomerCurrencyRefValue = loJsonResponse.StringOf("Customer.CurrencyRef.value") lcCustomerDefaultTaxCodeRefValue = loJsonResponse.StringOf("Customer.DefaultTaxCodeRef.value") lcCustomerPreferredDeliveryMethod = loJsonResponse.StringOf("Customer.PreferredDeliveryMethod") lcCustomerGivenName = loJsonResponse.StringOf("Customer.GivenName") lcCustomerFullyQualifiedName = loJsonResponse.StringOf("Customer.FullyQualifiedName") llCustomerBillWithParent = loJsonResponse.BoolOf("Customer.BillWithParent") lcCustomerTitle = loJsonResponse.StringOf("Customer.Title") llCustomerJob = loJsonResponse.BoolOf("Customer.Job") lnCustomerBalanceWithJobs = loJsonResponse.IntOf("Customer.BalanceWithJobs") lcCustomerPrimaryPhoneFreeFormNumber = loJsonResponse.StringOf("Customer.PrimaryPhone.FreeFormNumber") llCustomerTaxable = loJsonResponse.BoolOf("Customer.Taxable") lcCustomerMetaDataCreateTime = loJsonResponse.StringOf("Customer.MetaData.CreateTime") lcCustomerMetaDataLastUpdatedTime = loJsonResponse.StringOf("Customer.MetaData.LastUpdatedTime") lcCustomerBillAddrCity = loJsonResponse.StringOf("Customer.BillAddr.City") lcCustomerBillAddrCountry = loJsonResponse.StringOf("Customer.BillAddr.Country") lcCustomerBillAddrLine1 = loJsonResponse.StringOf("Customer.BillAddr.Line1") lcCustomerBillAddrPostalCode = loJsonResponse.StringOf("Customer.BillAddr.PostalCode") lcCustomerBillAddrCountrySubDivisionCode = loJsonResponse.StringOf("Customer.BillAddr.CountrySubDivisionCode") lcCustomerBillAddrId = loJsonResponse.StringOf("Customer.BillAddr.Id") lcCustomerMiddleName = loJsonResponse.StringOf("Customer.MiddleName") lcCustomerNotes = loJsonResponse.StringOf("Customer.Notes") llCustomerActive = loJsonResponse.BoolOf("Customer.Active") lnCustomerBalance = loJsonResponse.IntOf("Customer.Balance") lcCustomerSyncToken = loJsonResponse.StringOf("Customer.SyncToken") lcCustomerSuffix = loJsonResponse.StringOf("Customer.Suffix") lcCustomerCompanyName = loJsonResponse.StringOf("Customer.CompanyName") lcCustomerFamilyName = loJsonResponse.StringOf("Customer.FamilyName") lcCustomerPrintOnCheckName = loJsonResponse.StringOf("Customer.PrintOnCheckName") llCustomerSparse = loJsonResponse.BoolOf("Customer.sparse") lcCustomerId = loJsonResponse.StringOf("Customer.Id") lcTime = loJsonResponse.StringOf("time") release loJsonToken release loRest release loSbAuth release loJsonReq release loSbRequestBody release loSbResponseBody release loJsonResponse |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.