Visual FoxPro
Visual FoxPro
Quickbooks Create a New Customer
See more QuickBooks Examples
Demonstrates how to create a new customer via the Quickbooks REST API.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loJsonToken
LOCAL loRest
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbAuth
LOCAL loJsonReq
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJsonResponse
LOCAL lcCustomerDomain
LOCAL lcCustomerPrimaryEmailAddrAddress
LOCAL lcCustomerDisplayName
LOCAL lcCustomerCurrencyRefName
LOCAL lcCustomerCurrencyRefValue
LOCAL lcCustomerDefaultTaxCodeRefValue
LOCAL lcCustomerPreferredDeliveryMethod
LOCAL lcCustomerGivenName
LOCAL lcCustomerFullyQualifiedName
LOCAL lnCustomerBillWithParent
LOCAL lcCustomerTitle
LOCAL lnCustomerJob
LOCAL lnCustomerBalanceWithJobs
LOCAL lcCustomerPrimaryPhoneFreeFormNumber
LOCAL lnCustomerTaxable
LOCAL lcCustomerMetaDataCreateTime
LOCAL lcCustomerMetaDataLastUpdatedTime
LOCAL lcCustomerBillAddrCity
LOCAL lcCustomerBillAddrCountry
LOCAL lcCustomerBillAddrLine1
LOCAL lcCustomerBillAddrPostalCode
LOCAL lcCustomerBillAddrCountrySubDivisionCode
LOCAL lcCustomerBillAddrId
LOCAL lcCustomerMiddleName
LOCAL lcCustomerNotes
LOCAL lnCustomerActive
LOCAL lnCustomerBalance
LOCAL lcCustomerSyncToken
LOCAL lcCustomerSuffix
LOCAL lcCustomerCompanyName
LOCAL lcCustomerFamilyName
LOCAL lcCustomerPrintOnCheckName
LOCAL lnCustomerSparse
LOCAL lcCustomerId
LOCAL lcTime
lnSuccess = 0
* 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('Chilkat.JsonObject')
lnSuccess = loJsonToken.LoadFile("qa_data/tokens/qb-access-token.json")
loRest = CreateObject('Chilkat.Rest')
* Connect to the REST server.
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("sandbox-quickbooks.api.intuit.com",lnPort,lnBTls,lnBAutoReconnect)
loSbAuth = CreateObject('Chilkat.StringBuilder')
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('Chilkat.JsonObject')
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('Chilkat.StringBuilder')
loJsonReq.EmitSb(loSbRequestBody)
loRest.AddHeader("Content-Type","application/json")
loRest.AddHeader("Accept","application/json")
loRest.AllowHeaderFolding = 0
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/v3/company/<realmID>/customer",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loJsonToken
RELEASE loRest
RELEASE loSbAuth
RELEASE loJsonReq
RELEASE loSbRequestBody
RELEASE loSbResponseBody
CANCEL
ENDIF
lnRespStatusCode = loRest.ResponseStatusCode
* Success is indicated by a 200 response status code.
? "response status code = " + STR(lnRespStatusCode)
loJsonResponse = CreateObject('Chilkat.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)
loJsonResponse.EmitCompact = 0
? loJsonResponse.Emit()
IF (loRest.ResponseStatusCode <> 200) THEN
? "Failed."
RELEASE loJsonToken
RELEASE loRest
RELEASE loSbAuth
RELEASE loJsonReq
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJsonResponse
CANCEL
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")
lnCustomerBillWithParent = loJsonResponse.BoolOf("Customer.BillWithParent")
lcCustomerTitle = loJsonResponse.StringOf("Customer.Title")
lnCustomerJob = loJsonResponse.BoolOf("Customer.Job")
lnCustomerBalanceWithJobs = loJsonResponse.IntOf("Customer.BalanceWithJobs")
lcCustomerPrimaryPhoneFreeFormNumber = loJsonResponse.StringOf("Customer.PrimaryPhone.FreeFormNumber")
lnCustomerTaxable = 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")
lnCustomerActive = 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")
lnCustomerSparse = 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