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) Xero Get InvoicesGet Xero company invoices. For more information, see https://developer.xero.com/documentation/api/invoices
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; HCkJsonObjectW jsonToken; BOOL success; HCkHttpResponseW resp; HCkJsonObjectW jsonResponse; const wchar_t *Type; const wchar_t *InvoiceID; const wchar_t *InvoiceNumber; const wchar_t *Reference; const wchar_t *AmountDue; const wchar_t *AmountPaid; const wchar_t *AmountCredited; BOOL IsDiscounted; BOOL HasAttachments; BOOL HasErrors; const wchar_t *ContactContactID; const wchar_t *ContactName; BOOL ContactHasValidationErrors; const wchar_t *DateString; const wchar_t *Date; const wchar_t *DueDateString; const wchar_t *DueDate; const wchar_t *LineAmountTypes; const wchar_t *SubTotal; const wchar_t *TotalTax; const wchar_t *Total; const wchar_t *UpdatedDateUTC; const wchar_t *CurrencyCode; const wchar_t *FullyPaidOnDate; const wchar_t *CurrencyRate; int j; int count_j; const wchar_t *PaymentID; const wchar_t *Amount; BOOL HasAccount; BOOL HasValidationErrors; const wchar_t *CreditNoteID; const wchar_t *CreditNoteNumber; const wchar_t *ID; const wchar_t *AppliedAmount; int k; int count_k; const wchar_t *Id; const wchar_t *Status; const wchar_t *ProviderName; const wchar_t *DateTimeUTC; int i; int count_i; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); jsonToken = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/xero-access-token.json"); if (success == FALSE) { wprintf(L"%s\n",CkJsonObjectW_lastErrorText(jsonToken)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); return; } CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token")); // Replace the value here with an actual tenant ID obtained from this example: // Get Xero Tenant IDs CkHttpW_SetRequestHeader(http,L"Xero-tenant-id",L"83299b9e-5747-4a14-a18a-a6c94f824eb7"); CkHttpW_putAccept(http,L"application/json"); resp = CkHttpW_QuickRequest(http,L"GET",L"https://api.xero.com/api.xro/2.0/Invoices"); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); return; } wprintf(L"Response Status Code: %d\n",CkHttpResponseW_getStatusCode(resp)); jsonResponse = CkJsonObjectW_Create(); CkJsonObjectW_Load(jsonResponse,CkHttpResponseW_bodyStr(resp)); CkJsonObjectW_putEmitCompact(jsonResponse,FALSE); wprintf(L"%s\n",CkJsonObjectW_emit(jsonResponse)); if (CkHttpResponseW_getStatusCode(resp) != 200) { wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(jsonResponse); return; } CkHttpResponseW_Dispose(resp); // Sample output... // (See the parsing code below..) // // Use the this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // { // "Id": "bda1f62f-0d63-4178-8d54-e91fd226987a", // "Status": "OK", // "ProviderName": "Chilkat2222", // "DateTimeUTC": "\/Date(1587210234493)\/", // "Invoices": [ // { // "Type": "ACCPAY", // "InvoiceID": "0032f627-3156-4d30-9b1c-4d3b994dc921", // "InvoiceNumber": "9871", // "Reference": "", // "Payments": [ // { // "PaymentID": "22974891-3689-4694-9ee7-fd2ba917af55", // "Date": "\/Date(1579737600000+0000)\/", // "Amount": 148.50, // "Reference": "Chq 409", // "HasAccount": false, // "HasValidationErrors": false // } // ], // "CreditNotes": [ // ], // "Prepayments": [ // ], // "Overpayments": [ // ], // "AmountDue": 0.00, // "AmountPaid": 148.50, // "AmountCredited": 0.00, // "IsDiscounted": false, // "HasAttachments": false, // "HasErrors": false, // "Contact": { // "ContactID": "d6a384fb-f46f-41a3-8ac7-b7bc9e0b5efa", // "Name": "Melrose Parking", // "Addresses": [ // ], // "Phones": [ // ], // "ContactGroups": [ // ], // "ContactPersons": [ // ], // "HasValidationErrors": false // }, // "DateString": "2020-01-15T00:00:00", // "Date": "\/Date(1579046400000+0000)\/", // "DueDateString": "2020-01-24T00:00:00", // "DueDate": "\/Date(1579824000000+0000)\/", // "Status": "PAID", // "LineAmountTypes": "Exclusive", // "LineItems": [ // ], // "SubTotal": 135.00, // "TotalTax": 13.50, // "Total": 148.50, // "UpdatedDateUTC": "\/Date(1221560931500+0000)\/", // "CurrencyCode": "AUD", // "FullyPaidOnDate": "\/Date(1579737600000+0000)\/" // }, // { // "Type": "ACCPAY", // "InvoiceID": "673dd7cc-beb7-4697-83d4-0c47cb400cc2", // "InvoiceNumber": "", // "Reference": "", // "Payments": [ // { // "PaymentID": "4d06f609-5200-4364-9c8b-d4379a945252", // "Date": "\/Date(1580688000000+0000)\/", // "Amount": 974.60, // "Reference": "DD # 96013", // "HasAccount": false, // "HasValidationErrors": false // } // ], // "CreditNotes": [ // { // "CreditNoteID": "7df8949c-b71f-40c0-bbcf-39f2f450f286", // "CreditNoteNumber": "03391", // "ID": "7df8949c-b71f-40c0-bbcf-39f2f450f286", // "HasErrors": false, // "AppliedAmount": 218.90, // "DateString": "2020-01-29T00:00:00", // "Date": "\/Date(1580256000000+0000)\/", // "LineItems": [ // ], // "Total": 218.90 // } // ], // "Prepayments": [ // ], // "Overpayments": [ // ], // "AmountDue": 0.00, // "AmountPaid": 974.60, // "AmountCredited": 218.90, // "IsDiscounted": false, // "HasAttachments": false, // "HasErrors": false, // "Contact": { // "ContactID": "d0cd2c4f-18a0-4f7c-a32a-2db00f29d298", // "Name": "PC Complete", // "Addresses": [ // ], // "Phones": [ // ], // "ContactGroups": [ // ], // "ContactPersons": [ // ], // "HasValidationErrors": false // }, // "DateString": "2020-01-28T00:00:00", // "Date": "\/Date(1580169600000+0000)\/", // "DueDateString": "2020-02-04T00:00:00", // "DueDate": "\/Date(1580774400000+0000)\/", // "Status": "PAID", // "LineAmountTypes": "Exclusive", // "LineItems": [ // ], // "SubTotal": 1085.00, // "TotalTax": 108.50, // "Total": 1193.50, // "UpdatedDateUTC": "\/Date(1221561913790+0000)\/", // "CurrencyCode": "AUD", // "FullyPaidOnDate": "\/Date(1580688000000+0000)\/" // }, // { // "Type": "ACCPAY", // "InvoiceID": "c12aff7e-12bf-4185-8702-460929f19674", // "InvoiceNumber": "", // "Reference": "", // "Payments": [ // ], // "CreditNotes": [ // ], // "Prepayments": [ // ], // "Overpayments": [ // ], // "AmountDue": 2166.99, // "AmountPaid": 0.00, // "AmountCredited": 0.00, // "CurrencyRate": 1.000000, // "IsDiscounted": false, // "HasAttachments": false, // "HasErrors": false, // "Contact": { // "ContactID": "d0cd2c4f-18a0-4f7c-a32a-2db00f29d298", // "Name": "PC Complete", // "Addresses": [ // ], // "Phones": [ // ], // "ContactGroups": [ // ], // "ContactPersons": [ // ], // "HasValidationErrors": false // }, // "DateString": "2020-04-10T00:00:00", // "Date": "\/Date(1586476800000+0000)\/", // "DueDateString": "2020-05-05T00:00:00", // "DueDate": "\/Date(1588636800000+0000)\/", // "Status": "AUTHORISED", // "LineAmountTypes": "Exclusive", // "LineItems": [ // ], // "SubTotal": 1969.99, // "TotalTax": 197.00, // "Total": 2166.99, // "UpdatedDateUTC": "\/Date(1497965301980+0000)\/", // "CurrencyCode": "AUD" // } // ] // } // // 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. Id = CkJsonObjectW_stringOf(jsonResponse,L"Id"); Status = CkJsonObjectW_stringOf(jsonResponse,L"Status"); ProviderName = CkJsonObjectW_stringOf(jsonResponse,L"ProviderName"); DateTimeUTC = CkJsonObjectW_stringOf(jsonResponse,L"DateTimeUTC"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices"); while (i < count_i) { CkJsonObjectW_putI(jsonResponse,i); Type = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Type"); InvoiceID = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].InvoiceID"); InvoiceNumber = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].InvoiceNumber"); Reference = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Reference"); AmountDue = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].AmountDue"); AmountPaid = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].AmountPaid"); AmountCredited = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].AmountCredited"); IsDiscounted = CkJsonObjectW_BoolOf(jsonResponse,L"Invoices[i].IsDiscounted"); HasAttachments = CkJsonObjectW_BoolOf(jsonResponse,L"Invoices[i].HasAttachments"); HasErrors = CkJsonObjectW_BoolOf(jsonResponse,L"Invoices[i].HasErrors"); ContactContactID = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Contact.ContactID"); ContactName = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Contact.Name"); ContactHasValidationErrors = CkJsonObjectW_BoolOf(jsonResponse,L"Invoices[i].Contact.HasValidationErrors"); DateString = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].DateString"); Date = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Date"); DueDateString = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].DueDateString"); DueDate = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].DueDate"); Status = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Status"); LineAmountTypes = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].LineAmountTypes"); SubTotal = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].SubTotal"); TotalTax = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].TotalTax"); Total = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Total"); UpdatedDateUTC = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].UpdatedDateUTC"); CurrencyCode = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].CurrencyCode"); FullyPaidOnDate = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].FullyPaidOnDate"); CurrencyRate = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].CurrencyRate"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].Payments"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); PaymentID = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Payments[j].PaymentID"); Date = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Payments[j].Date"); Amount = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Payments[j].Amount"); Reference = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].Payments[j].Reference"); HasAccount = CkJsonObjectW_BoolOf(jsonResponse,L"Invoices[i].Payments[j].HasAccount"); HasValidationErrors = CkJsonObjectW_BoolOf(jsonResponse,L"Invoices[i].Payments[j].HasValidationErrors"); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].CreditNotes"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); CreditNoteID = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].CreditNotes[j].CreditNoteID"); CreditNoteNumber = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].CreditNotes[j].CreditNoteNumber"); ID = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].CreditNotes[j].ID"); HasErrors = CkJsonObjectW_BoolOf(jsonResponse,L"Invoices[i].CreditNotes[j].HasErrors"); AppliedAmount = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].CreditNotes[j].AppliedAmount"); DateString = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].CreditNotes[j].DateString"); Date = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].CreditNotes[j].Date"); Total = CkJsonObjectW_stringOf(jsonResponse,L"Invoices[i].CreditNotes[j].Total"); k = 0; count_k = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].CreditNotes[j].LineItems"); while (k < count_k) { CkJsonObjectW_putK(jsonResponse,k); k = k + 1; } j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].Prepayments"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].Overpayments"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].Contact.Addresses"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].Contact.Phones"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].Contact.ContactGroups"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].Contact.ContactPersons"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"Invoices[i].LineItems"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); j = j + 1; } i = i + 1; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(jsonResponse); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.