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
(Objective-C) Quickbooks Send an InvoiceDemonstrates how to send an invoice using the Quickbooks REST API. For more information, see https://www.developer.intuit.com/app/developer/qbo/docs/api/accounting/most-commonly-used/invoice#send-an-invoice
#import <CkoJsonObject.h> #import <CkoRest.h> #import <CkoStringBuilder.h> #import <NSString.h> // 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. CkoJsonObject *jsonToken = [[CkoJsonObject alloc] init]; BOOL success = [jsonToken LoadFile: @"qa_data/tokens/qb-access-token.json"]; CkoRest *rest = [[CkoRest alloc] init]; // Connect to the REST server. BOOL bTls = YES; int port = 443; BOOL bAutoReconnect = YES; BOOL success = [rest Connect: @"sandbox-quickbooks.api.intuit.com" port: [NSNumber numberWithInt: port] tls: bTls autoReconnect: bAutoReconnect]; CkoStringBuilder *sbAuth = [[CkoStringBuilder alloc] init]; [sbAuth Append: @"Bearer "]; [sbAuth Append: [jsonToken StringOf: @"access_token"]]; rest.Authorization = [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. // -------------------------------------------------------------------------- // Technically, the POST has an empty request body, but the Quickbooks documentation indicates that // the Content-Type header should be set to "application/octet-stream", which really makes no sense // because there is not content. (How can no content have a type???) [rest AddHeader: @"Content-Type" value: @"application/octet-stream"]; rest.AllowHeaderFolding = NO; CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init]; success = [rest FullRequestNoBodySb: @"POST" uriPath: @"/v3/company/<realmID>/invoice/<invoiceId>/send?sendTo=<emailAddr>" sb: sbResponseBody]; if (success != YES) { NSLog(@"%@",rest.LastErrorText); return; } int respStatusCode = [rest.ResponseStatusCode intValue]; // Success is indicated by a 200 response status code. NSLog(@"%@%d",@"response status code = ",respStatusCode); CkoJsonObject *jsonResponse = [[CkoJsonObject alloc] init]; [jsonResponse LoadSb: sbResponseBody]; jsonResponse.EmitCompact = NO; NSLog(@"%@",[jsonResponse Emit]); if ([rest.ResponseStatusCode intValue] != 200) { NSLog(@"%@",@"Failed."); return; } // Sample output... // (See the parsing code below..) // // Use the this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // { // "Invoice": { // "TxnDate": "2013-03-14", // "domain": "QBO", // "CurrencyRef": { // "name": "United States Dollar", // "value": "USD" // }, // "ShipDate": "2013-03-01", // "TrackingNum": "123456789", // "ClassRef": { // "name": "Class 1", // "value": "200900000000000003901" // }, // "PrintStatus": "NeedToPrint", // "SalesTermRef": { // "value": "4" // }, // "DeliveryInfo": { // "DeliveryType": "Email", // "DeliveryTime": "2014-12-17T11:50:52-08:00" // }, // "TotalAmt": 52.0, // "Line": [ // { // "Description": "Sample invoice create request", // "DetailType": "SalesItemLineDetail", // "SalesItemLineDetail": { // "TaxCodeRef": { // "value": "TAX" // }, // "Qty": 1, // "UnitPrice": 50, // "ServiceDate": "2013-03-04", // "ItemRef": { // "name": "Hours", // "value": "2" // } // }, // "LineNum": 1, // "Amount": 50.0, // "Id": "1" // }, // { // "DetailType": "SubTotalLineDetail", // "Amount": 50.0, // "SubTotalLineDetail": {} // }, // { // "DetailType": "DiscountLineDetail", // "Amount": 5.0, // "DiscountLineDetail": { // "DiscountAccountRef": { // "name": "Discounts given", // "value": "30" // }, // "PercentBased": true, // "DiscountPercent": 10 // } // }, // { // "DetailType": "SalesItemLineDetail", // "Amount": 2.0, // "SalesItemLineDetail": { // "ItemRef": { // "value": "SHIPPING_ITEM_ID" // } // } // } // ], // "DueDate": "2013-05-13", // "MetaData": { // "CreateTime": "2013-03-14T01:42:16-07:00", // "LastUpdatedTime": "2014-12-17T11:50:58-08:00" // }, // "DocNumber": "Sample_Inv#2", // "PrivateNote": "Summary for sample invoice", // "sparse": false, // "DepositToAccountRef": { // "name": "Undeposited Funds", // "value": "4" // }, // "CustomerMemo": { // "value": "This is the customer message" // }, // "EmailStatus": "EmailSent", // "Deposit": 12.0, // "Balance": 40.0, // "CustomerRef": { // "name": "Mr V3 Service Customer Jr2", // "value": "15" // }, // "TxnTaxDetail": { // "TxnTaxCodeRef": { // "value": "5" // }, // "TotalTax": 5.0, // "TaxLine": [ // { // "DetailType": "TaxLineDetail", // "Amount": 5.0, // "TaxLineDetail": { // "NetAmountTaxable": 50.0, // "TaxPercent": 10, // "TaxRateRef": { // "value": "2" // }, // "PercentBased": true // } // } // ] // }, // "SyncToken": "0", // "BillEmail": { // "Address": "test@intuit.com" // }, // "ShipAddr": { // "City": "San Jose", // "Country": "USA", // "Line5": "Cube 999", // "Line4": "Dept 12", // "Line3": "123 street", // "Line2": "Building 1", // "Line1": "Intuit", // "PostalCode": "95123", // "Lat": "37.2374847", // "Long": "-121.8277925", // "CountrySubDivisionCode": "CA", // "Id": "36" // }, // "DepartmentRef": { // "name": "Mountain View", // "value": "1" // }, // "ShipMethodRef": { // "name": "UPS", // "value": "UPS" // }, // "BillAddr": { // "City": "Mountain View", // "Country": "USA", // "Line5": "Cube 999", // "Line4": "Dept 12", // "Line3": "123 street", // "Line2": "Building 1", // "Line1": "Google", // "PostalCode": "95123", // "Lat": "37.2374847", // "Long": "-121.8277925", // "CountrySubDivisionCode": "CA", // "Id": "35" // }, // "ApplyTaxAfterDiscount": false, // "CustomField": [ // { // "StringValue": "Custom1", // "Type": "StringType", // "Name": "Custom 1" // }, // { // "StringValue": "Custom2", // "Type": "StringType", // "Name": "Custom 2" // }, // { // "StringValue": "Custom3", // "Type": "StringType", // "Name": "Custom 3" // } // ], // "Id": "96" // }, // "time": "2013-03-14T13:32:04.895-07:00" // } // NSString *Description = 0; NSString *DetailType = 0; NSString *SalesItemLineDetailTaxCodeRefValue = 0; int SalesItemLineDetailQty; int SalesItemLineDetailUnitPrice; NSString *SalesItemLineDetailServiceDate = 0; NSString *SalesItemLineDetailItemRefName = 0; NSString *SalesItemLineDetailItemRefValue = 0; int LineNum; NSString *Amount = 0; NSString *Id = 0; NSString *DiscountLineDetailDiscountAccountRefName = 0; NSString *DiscountLineDetailDiscountAccountRefValue = 0; BOOL DiscountLineDetailPercentBased; int DiscountLineDetailDiscountPercent; NSString *TaxLineDetailNetAmountTaxable = 0; int TaxLineDetailTaxPercent; NSString *TaxLineDetailTaxRateRefValue = 0; BOOL TaxLineDetailPercentBased; NSString *StringValue = 0; NSString *Type = 0; NSString *Name = 0; NSString *InvoiceTxnDate = [jsonResponse StringOf: @"Invoice.TxnDate"]; NSString *InvoiceDomain = [jsonResponse StringOf: @"Invoice.domain"]; NSString *InvoiceCurrencyRefName = [jsonResponse StringOf: @"Invoice.CurrencyRef.name"]; NSString *InvoiceCurrencyRefValue = [jsonResponse StringOf: @"Invoice.CurrencyRef.value"]; NSString *InvoiceShipDate = [jsonResponse StringOf: @"Invoice.ShipDate"]; NSString *InvoiceTrackingNum = [jsonResponse StringOf: @"Invoice.TrackingNum"]; NSString *InvoiceClassRefName = [jsonResponse StringOf: @"Invoice.ClassRef.name"]; NSString *InvoiceClassRefValue = [jsonResponse StringOf: @"Invoice.ClassRef.value"]; NSString *InvoicePrintStatus = [jsonResponse StringOf: @"Invoice.PrintStatus"]; NSString *InvoiceSalesTermRefValue = [jsonResponse StringOf: @"Invoice.SalesTermRef.value"]; NSString *InvoiceDeliveryInfoDeliveryType = [jsonResponse StringOf: @"Invoice.DeliveryInfo.DeliveryType"]; NSString *InvoiceDeliveryInfoDeliveryTime = [jsonResponse StringOf: @"Invoice.DeliveryInfo.DeliveryTime"]; NSString *InvoiceTotalAmt = [jsonResponse StringOf: @"Invoice.TotalAmt"]; NSString *InvoiceDueDate = [jsonResponse StringOf: @"Invoice.DueDate"]; NSString *InvoiceMetaDataCreateTime = [jsonResponse StringOf: @"Invoice.MetaData.CreateTime"]; NSString *InvoiceMetaDataLastUpdatedTime = [jsonResponse StringOf: @"Invoice.MetaData.LastUpdatedTime"]; NSString *InvoiceDocNumber = [jsonResponse StringOf: @"Invoice.DocNumber"]; NSString *InvoicePrivateNote = [jsonResponse StringOf: @"Invoice.PrivateNote"]; BOOL InvoiceSparse = [jsonResponse BoolOf: @"Invoice.sparse"]; NSString *InvoiceDepositToAccountRefName = [jsonResponse StringOf: @"Invoice.DepositToAccountRef.name"]; NSString *InvoiceDepositToAccountRefValue = [jsonResponse StringOf: @"Invoice.DepositToAccountRef.value"]; NSString *InvoiceCustomerMemoValue = [jsonResponse StringOf: @"Invoice.CustomerMemo.value"]; NSString *InvoiceEmailStatus = [jsonResponse StringOf: @"Invoice.EmailStatus"]; NSString *InvoiceDeposit = [jsonResponse StringOf: @"Invoice.Deposit"]; NSString *InvoiceBalance = [jsonResponse StringOf: @"Invoice.Balance"]; NSString *InvoiceCustomerRefName = [jsonResponse StringOf: @"Invoice.CustomerRef.name"]; NSString *InvoiceCustomerRefValue = [jsonResponse StringOf: @"Invoice.CustomerRef.value"]; NSString *InvoiceTxnTaxDetailTxnTaxCodeRefValue = [jsonResponse StringOf: @"Invoice.TxnTaxDetail.TxnTaxCodeRef.value"]; NSString *InvoiceTxnTaxDetailTotalTax = [jsonResponse StringOf: @"Invoice.TxnTaxDetail.TotalTax"]; NSString *InvoiceSyncToken = [jsonResponse StringOf: @"Invoice.SyncToken"]; NSString *InvoiceBillEmailAddress = [jsonResponse StringOf: @"Invoice.BillEmail.Address"]; NSString *InvoiceShipAddrCity = [jsonResponse StringOf: @"Invoice.ShipAddr.City"]; NSString *InvoiceShipAddrCountry = [jsonResponse StringOf: @"Invoice.ShipAddr.Country"]; NSString *InvoiceShipAddrLine5 = [jsonResponse StringOf: @"Invoice.ShipAddr.Line5"]; NSString *InvoiceShipAddrLine4 = [jsonResponse StringOf: @"Invoice.ShipAddr.Line4"]; NSString *InvoiceShipAddrLine3 = [jsonResponse StringOf: @"Invoice.ShipAddr.Line3"]; NSString *InvoiceShipAddrLine2 = [jsonResponse StringOf: @"Invoice.ShipAddr.Line2"]; NSString *InvoiceShipAddrLine1 = [jsonResponse StringOf: @"Invoice.ShipAddr.Line1"]; NSString *InvoiceShipAddrPostalCode = [jsonResponse StringOf: @"Invoice.ShipAddr.PostalCode"]; NSString *InvoiceShipAddrLat = [jsonResponse StringOf: @"Invoice.ShipAddr.Lat"]; NSString *InvoiceShipAddrLong = [jsonResponse StringOf: @"Invoice.ShipAddr.Long"]; NSString *InvoiceShipAddrCountrySubDivisionCode = [jsonResponse StringOf: @"Invoice.ShipAddr.CountrySubDivisionCode"]; NSString *InvoiceShipAddrId = [jsonResponse StringOf: @"Invoice.ShipAddr.Id"]; NSString *InvoiceDepartmentRefName = [jsonResponse StringOf: @"Invoice.DepartmentRef.name"]; NSString *InvoiceDepartmentRefValue = [jsonResponse StringOf: @"Invoice.DepartmentRef.value"]; NSString *InvoiceShipMethodRefName = [jsonResponse StringOf: @"Invoice.ShipMethodRef.name"]; NSString *InvoiceShipMethodRefValue = [jsonResponse StringOf: @"Invoice.ShipMethodRef.value"]; NSString *InvoiceBillAddrCity = [jsonResponse StringOf: @"Invoice.BillAddr.City"]; NSString *InvoiceBillAddrCountry = [jsonResponse StringOf: @"Invoice.BillAddr.Country"]; NSString *InvoiceBillAddrLine5 = [jsonResponse StringOf: @"Invoice.BillAddr.Line5"]; NSString *InvoiceBillAddrLine4 = [jsonResponse StringOf: @"Invoice.BillAddr.Line4"]; NSString *InvoiceBillAddrLine3 = [jsonResponse StringOf: @"Invoice.BillAddr.Line3"]; NSString *InvoiceBillAddrLine2 = [jsonResponse StringOf: @"Invoice.BillAddr.Line2"]; NSString *InvoiceBillAddrLine1 = [jsonResponse StringOf: @"Invoice.BillAddr.Line1"]; NSString *InvoiceBillAddrPostalCode = [jsonResponse StringOf: @"Invoice.BillAddr.PostalCode"]; NSString *InvoiceBillAddrLat = [jsonResponse StringOf: @"Invoice.BillAddr.Lat"]; NSString *InvoiceBillAddrLong = [jsonResponse StringOf: @"Invoice.BillAddr.Long"]; NSString *InvoiceBillAddrCountrySubDivisionCode = [jsonResponse StringOf: @"Invoice.BillAddr.CountrySubDivisionCode"]; NSString *InvoiceBillAddrId = [jsonResponse StringOf: @"Invoice.BillAddr.Id"]; BOOL InvoiceApplyTaxAfterDiscount = [jsonResponse BoolOf: @"Invoice.ApplyTaxAfterDiscount"]; NSString *InvoiceId = [jsonResponse StringOf: @"Invoice.Id"]; NSString *time = [jsonResponse StringOf: @"time"]; int i = 0; int count_i = [[jsonResponse SizeOfArray: @"Invoice.Line"] intValue]; while (i < count_i) { jsonResponse.I = [NSNumber numberWithInt: i]; Description = [jsonResponse StringOf: @"Invoice.Line[i].Description"]; DetailType = [jsonResponse StringOf: @"Invoice.Line[i].DetailType"]; SalesItemLineDetailTaxCodeRefValue = [jsonResponse StringOf: @"Invoice.Line[i].SalesItemLineDetail.TaxCodeRef.value"]; SalesItemLineDetailQty = [[jsonResponse IntOf: @"Invoice.Line[i].SalesItemLineDetail.Qty"] intValue]; SalesItemLineDetailUnitPrice = [[jsonResponse IntOf: @"Invoice.Line[i].SalesItemLineDetail.UnitPrice"] intValue]; SalesItemLineDetailServiceDate = [jsonResponse StringOf: @"Invoice.Line[i].SalesItemLineDetail.ServiceDate"]; SalesItemLineDetailItemRefName = [jsonResponse StringOf: @"Invoice.Line[i].SalesItemLineDetail.ItemRef.name"]; SalesItemLineDetailItemRefValue = [jsonResponse StringOf: @"Invoice.Line[i].SalesItemLineDetail.ItemRef.value"]; LineNum = [[jsonResponse IntOf: @"Invoice.Line[i].LineNum"] intValue]; Amount = [jsonResponse StringOf: @"Invoice.Line[i].Amount"]; Id = [jsonResponse StringOf: @"Invoice.Line[i].Id"]; DiscountLineDetailDiscountAccountRefName = [jsonResponse StringOf: @"Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.name"]; DiscountLineDetailDiscountAccountRefValue = [jsonResponse StringOf: @"Invoice.Line[i].DiscountLineDetail.DiscountAccountRef.value"]; DiscountLineDetailPercentBased = [jsonResponse BoolOf: @"Invoice.Line[i].DiscountLineDetail.PercentBased"]; DiscountLineDetailDiscountPercent = [[jsonResponse IntOf: @"Invoice.Line[i].DiscountLineDetail.DiscountPercent"] intValue]; i = i + 1; } i = 0; count_i = [[jsonResponse SizeOfArray: @"Invoice.TxnTaxDetail.TaxLine"] intValue]; while (i < count_i) { jsonResponse.I = [NSNumber numberWithInt: i]; DetailType = [jsonResponse StringOf: @"Invoice.TxnTaxDetail.TaxLine[i].DetailType"]; Amount = [jsonResponse StringOf: @"Invoice.TxnTaxDetail.TaxLine[i].Amount"]; TaxLineDetailNetAmountTaxable = [jsonResponse StringOf: @"Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.NetAmountTaxable"]; TaxLineDetailTaxPercent = [[jsonResponse IntOf: @"Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxPercent"] intValue]; TaxLineDetailTaxRateRefValue = [jsonResponse StringOf: @"Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.TaxRateRef.value"]; TaxLineDetailPercentBased = [jsonResponse BoolOf: @"Invoice.TxnTaxDetail.TaxLine[i].TaxLineDetail.PercentBased"]; i = i + 1; } i = 0; count_i = [[jsonResponse SizeOfArray: @"Invoice.CustomField"] intValue]; while (i < count_i) { jsonResponse.I = [NSNumber numberWithInt: i]; StringValue = [jsonResponse StringOf: @"Invoice.CustomField[i].StringValue"]; Type = [jsonResponse StringOf: @"Invoice.CustomField[i].Type"]; Name = [jsonResponse StringOf: @"Invoice.CustomField[i].Name"]; i = i + 1; } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.