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
(Unicode C) Quickbooks Query an InvoiceDemonstrates 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
#include <C_CkJsonObjectW.h> #include <C_CkRestW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkJsonObjectW jsonToken; BOOL success; HCkRestW rest; BOOL bTls; int port; BOOL bAutoReconnect; BOOL success; HCkStringBuilderW sbAuth; HCkStringBuilderW sbResponseBody; int respStatusCode; HCkJsonObjectW json; const wchar_t *DocNumber; const wchar_t *SyncToken; const wchar_t *domain; const wchar_t *Balance; const wchar_t *BillAddrCity; const wchar_t *BillAddrLine1; const wchar_t *BillAddrPostalCode; const wchar_t *BillAddrLat; const wchar_t *BillAddrLong; const wchar_t *BillAddrCountrySubDivisionCode; const wchar_t *BillAddrId; const wchar_t *TxnDate; const wchar_t *TotalAmt; const wchar_t *CustomerRefName; const wchar_t *CustomerRefValue; const wchar_t *ShipAddrCity; const wchar_t *ShipAddrLine1; const wchar_t *ShipAddrPostalCode; const wchar_t *ShipAddrLat; const wchar_t *ShipAddrLong; const wchar_t *ShipAddrCountrySubDivisionCode; const wchar_t *ShipAddrId; const wchar_t *DueDate; const wchar_t *PrintStatus; int Deposit; BOOL sparse; const wchar_t *EmailStatus; BOOL ApplyTaxAfterDiscount; const wchar_t *Id; int TxnTaxDetailTotalTax; const wchar_t *MetaDataCreateTime; const wchar_t *MetaDataLastUpdatedTime; int j; int count_j; int LineNum; const wchar_t *Amount; const wchar_t *SalesItemLineDetailTaxCodeRefValue; const wchar_t *SalesItemLineDetailItemRefName; const wchar_t *SalesItemLineDetailItemRefValue; const wchar_t *DetailType; const wchar_t *DefinitionId; const wchar_t *invType; const wchar_t *Name; int QueryResponseStartPosition; int QueryResponseTotalCount; int QueryResponseMaxResults; const wchar_t *time; int i; int count_i; // 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. jsonToken = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/qb-access-token.json"); rest = CkRestW_Create(); bTls = TRUE; port = 443; bAutoReconnect = TRUE; success = CkRestW_Connect(rest,L"sandbox-quickbooks.api.intuit.com",port,bTls,bAutoReconnect); sbAuth = CkStringBuilderW_Create(); CkStringBuilderW_Append(sbAuth,L"Bearer "); CkStringBuilderW_Append(sbAuth,CkJsonObjectW_stringOf(jsonToken,L"access_token")); CkRestW_putAuthorization(rest,CkStringBuilderW_getAsString(sbAuth)); // -------------------------------------------------------------------------- // 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.. CkRestW_RemoveHeader(rest,L"Content-Type"); CkRestW_AddHeader(rest,L"Accept",L"application/json"); CkRestW_putAllowHeaderFolding(rest,FALSE); // Add a SELECT statement CkRestW_AddQueryParam(rest,L"query",L"select * from Invoice where id = '239'"); sbResponseBody = CkStringBuilderW_Create(); success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/v3/company/<realmID>/invoice",sbResponseBody); if (success != TRUE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkJsonObjectW_Dispose(jsonToken); CkRestW_Dispose(rest); CkStringBuilderW_Dispose(sbAuth); CkStringBuilderW_Dispose(sbResponseBody); return; } respStatusCode = CkRestW_getResponseStatusCode(rest); if (respStatusCode >= 400) { wprintf(L"Response Status Code = %d\n",respStatusCode); wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkRestW_responseHeader(rest)); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody)); CkJsonObjectW_Dispose(jsonToken); CkRestW_Dispose(rest); CkStringBuilderW_Dispose(sbAuth); CkStringBuilderW_Dispose(sbResponseBody); return; } // Success is indicated by a 200 response status. wprintf(L"response status code = %d\n",respStatusCode); json = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(json,sbResponseBody); CkJsonObjectW_putEmitCompact(json,FALSE); wprintf(L"%s\n",CkJsonObjectW_emit(json)); // 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" // } // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. QueryResponseStartPosition = CkJsonObjectW_IntOf(json,L"QueryResponse.startPosition"); QueryResponseTotalCount = CkJsonObjectW_IntOf(json,L"QueryResponse.totalCount"); QueryResponseMaxResults = CkJsonObjectW_IntOf(json,L"QueryResponse.maxResults"); time = CkJsonObjectW_stringOf(json,L"time"); i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"QueryResponse.Invoice"); while (i < count_i) { CkJsonObjectW_putI(json,i); DocNumber = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].DocNumber"); SyncToken = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].SyncToken"); domain = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].domain"); Balance = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].Balance"); BillAddrCity = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].BillAddr.City"); BillAddrLine1 = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].BillAddr.Line1"); BillAddrPostalCode = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].BillAddr.PostalCode"); BillAddrLat = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].BillAddr.Lat"); BillAddrLong = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].BillAddr.Long"); BillAddrCountrySubDivisionCode = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].BillAddr.CountrySubDivisionCode"); BillAddrId = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].BillAddr.Id"); TxnDate = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].TxnDate"); TotalAmt = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].TotalAmt"); CustomerRefName = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].CustomerRef.name"); CustomerRefValue = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].CustomerRef.value"); ShipAddrCity = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].ShipAddr.City"); ShipAddrLine1 = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].ShipAddr.Line1"); ShipAddrPostalCode = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].ShipAddr.PostalCode"); ShipAddrLat = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].ShipAddr.Lat"); ShipAddrLong = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].ShipAddr.Long"); ShipAddrCountrySubDivisionCode = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].ShipAddr.CountrySubDivisionCode"); ShipAddrId = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].ShipAddr.Id"); DueDate = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].DueDate"); PrintStatus = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].PrintStatus"); Deposit = CkJsonObjectW_IntOf(json,L"QueryResponse.Invoice[i].Deposit"); sparse = CkJsonObjectW_BoolOf(json,L"QueryResponse.Invoice[i].sparse"); EmailStatus = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].EmailStatus"); ApplyTaxAfterDiscount = CkJsonObjectW_BoolOf(json,L"QueryResponse.Invoice[i].ApplyTaxAfterDiscount"); Id = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].Id"); TxnTaxDetailTotalTax = CkJsonObjectW_IntOf(json,L"QueryResponse.Invoice[i].TxnTaxDetail.TotalTax"); MetaDataCreateTime = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].MetaData.CreateTime"); MetaDataLastUpdatedTime = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].MetaData.LastUpdatedTime"); j = 0; count_j = CkJsonObjectW_SizeOfArray(json,L"QueryResponse.Invoice[i].LinkedTxn"); while (j < count_j) { CkJsonObjectW_putJ(json,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(json,L"QueryResponse.Invoice[i].Line"); while (j < count_j) { CkJsonObjectW_putJ(json,j); LineNum = CkJsonObjectW_IntOf(json,L"QueryResponse.Invoice[i].Line[j].LineNum"); Amount = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].Line[j].Amount"); SalesItemLineDetailTaxCodeRefValue = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.TaxCodeRef.value"); SalesItemLineDetailItemRefName = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.ItemRef.name"); SalesItemLineDetailItemRefValue = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].Line[j].SalesItemLineDetail.ItemRef.value"); Id = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].Line[j].Id"); DetailType = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].Line[j].DetailType"); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(json,L"QueryResponse.Invoice[i].CustomField"); while (j < count_j) { CkJsonObjectW_putJ(json,j); DefinitionId = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].CustomField[j].DefinitionId"); invType = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].CustomField[j].Type"); Name = CkJsonObjectW_stringOf(json,L"QueryResponse.Invoice[i].CustomField[j].Name"); j = j + 1; } i = i + 1; } CkJsonObjectW_Dispose(jsonToken); CkRestW_Dispose(rest); CkStringBuilderW_Dispose(sbAuth); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.