QuickBooks: Create a purchase
QuickBooks purchase.create: arguments, response, policy and SDK examples.
← Purchase operations · Get started
Operation quickbooks.purchase.create_a_purchase
Provider route: POST /v3/company/{realmID}/purchase. Alter supplies the connection’s credentials and routing.
Call through Alter
Section titled “Call through Alter”Install @alter-ai/sdk @alter-ai/quickbooks with npm, or alter-sdk-quickbooks with pip. Supply your connected customer’s grant ID and the arguments described below.
import { App } from "@alter-ai/sdk";import { QuickBooksIntegration } from "@alter-ai/quickbooks";
async function execute(input: Parameters<QuickBooksIntegration["purchase"]["create"]>[0]) { const app = new App({ apiKey: process.env.ALTER_API_KEY! }); try { const provider = new QuickBooksIntegration(app, { grantId: process.env.PROVIDER_GRANT_ID! }); const call = await provider.purchase.create(input); const result = await call.wait(); return result.bodyJson(); } finally { await app.close(); }}import osfrom alter_sdk import Appfrom alter_sdk_quickbooks import QuickBooksIntegration
async def execute(arguments): async with App(api_key=os.environ["ALTER_API_KEY"]) as app: provider = QuickBooksIntegration(app, {"grant_id": os.environ["PROVIDER_GRANT_ID"]}) call = await provider.purchase.create(arguments) result = await call.wait() return result.body_json()| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
query | object | Optional | Additional keys: not allowed |
query.minorversion | integer | Optional | Must equal: 75 |
query.requestid | string | Optional | Minimum length: 1 |
query.include | string | Optional | One of: allowduplicatedocnum, enhancedAllCustomFields |
body | object | Required within parent | Fields not accepted: Id, SyncToken Additional keys: not allowed |
body.AccountRef | Model | Required within parent | Expand Create a purchase order — request body — body Ship To Specifies the account reference. Check must specify bank account, CreditCard must specify credit card account. Validation Rules:Valid and Active Account Reference of an appropriate type. |
body.Credit | JSON | Optional | False —it represents a charge. True —it represents a refund. Valid only for CreditCard payment type. Validation Rules: Valid only for CreditCard transactions. |
body.Credit (anyOf 1) | boolean | Alternative | |
body.Credit (anyOf 2) | string | Alternative | One of: true, false |
body.CurrencyRef | Model | Optional | Expand Create a bill — request body — body Currency Ref Reference to the currency in which all amounts on the associated transaction are expressed. This must be defined if multicurrency is enabled for the company. Multicurrency is enabled for the company if Preferences.MultiCurrencyEnabled is set to true . Read more about multicurrency support here . Required if multicurrency is enabled for the company Conditionally required |
body.DepartmentRef | Model | Optional | Expand Create a purchase order — request body — body Ship To A reference to a Department object specifying the location of the transaction. Available if Preferences.AccountingInfoPrefs.TrackDepartments is set to true . Query the Department name list resource to determine the appropriate department object for this reference. Use Department.Id and Department.Name from that object for DepartmentRef.value and DepartmentRef.name , respectively. |
body.DocNumber | JSON | Optional | Reference number for the transaction. If not explicitly provided at create time, this field is populated based on the setting of Preferences:OtherPrefs:NameValue.Name = VendorAndPurchasesPrefs.UseCustomTxnNumbers as follows: If Preferences:OtherPrefs:NameValue.Name = VendorAndPurchasesPrefs.UseCustomTxnNumbers is true a custom value can be provided; duplicate values are not accepted. If no value is supplied, the resulting DocNumber is null. If Preferences:OtherPrefs:NameValue.Name = VendorAndPurchasesPrefs.UseCustomTxnNumbers is false, resulting DocNumber is system generated by incrementing the last number by 1. For Cash/CreditCard transactions, throws an error when duplicate DocNumber is sent in the request. For Check transactions, error is thrown when duplicate DocNumber is sent in the request and Preferences:OtherPrefs:NameValue.Name = WarnDuplicateCheckNumber is true. Recommended best practice: check the setting of Preferences:OtherPrefs:NameValue.Name = VendorAndPurchasesPrefs.UseCustomTxnNumbers before setting DocNumber. If a duplicate DocNumber needs to be supplied, add the query parameter name/value pair, include=allowduplicatedocnum to the URI. Sort order is ASC by default. |
body.DocNumber (anyOf 1) | string | Alternative | |
body.DocNumber (anyOf 2) | null | Alternative | |
body.EntityRef | Model | Optional | Expand Create a purchase order — request body — body Ship To Specifies the party with whom an expense is associated. Can be Customer , Vendor, or Employee. Query the corresponding name list resource of the associated type to determine the appropriate object for this reference. Use the Id and DisplayName values from that object for EntityRef.value and EntityRef.name , respectively. Set EntityRef.type to the type of object associated with this expense. For example, if this object represents a purchase from a vendor, then set EntityRef.type to Vendor and query the Vendor resource for the appropriate object to reference. |
body.ExchangeRate | JSON | Optional | The number of home currency units it takes to equal one unit of currency specified by CurrencyRef . Applicable if multicurrency is enabled for the company Decimal string |
body.ExchangeRate (anyOf 1) | number | Alternative | |
body.ExchangeRate (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:.[0-9]+)?$ |
body.GlobalTaxCalculation | string | Optional | Method in which tax is applied. Allowed values are: TaxExcluded , TaxInclusive , and NotApplicable . |
body.IncludeInAnnualTPAR | JSON | Optional | Include the supplier in the annual TPAR. TPAR stands for Taxable Payments Annual Report. The TPAR is mandated by ATO to get the details payments that businesses make to contractors for providing services. Some government entities also need to report the grants they have paid in a TPAR. |
body.IncludeInAnnualTPAR (anyOf 1) | boolean | Alternative | |
body.IncludeInAnnualTPAR (anyOf 2) | string | Alternative | One of: true, false |
body.Line | array | Required within parent | Individual line items of a transaction. Valid Line type for create: AccountBasedExpenseLine |
body.Line[] | Model | Each item | Expand Create a bill — request body — body Line item |
body.LinkedTxn | array | Optional | Zero or more transactions linked to this object. The LinkedTxn.TxnType can be set to ReimburseCharge . The LinkedTxn.TxnId can be set as the ID of the transaction. |
body.LinkedTxn[] | Model | Each item | Expand Create a bill — request body — body Linked Txn item |
body.MetaData | Model | Optional | Expand Read a bill — response body — Bill Meta Data Descriptive information about the object. The MetaData values are set by Data Services and are read only for all applications. |
body.PaymentMethodRef | Model | Optional | Expand Create a purchase order — request body — body Ship To Reference to a PaymentMethod associated with this transaction. Query the PaymentMethod name list resource to determine the appropriate PaymentMethod object for this reference. Use PaymentMethod.Id and PaymentMethod.Name from that object for PaymentMethodRef.value and PaymentMethodRef.name , respectively. |
body.PaymentType | string | Required within parent | Payment Type can be: Cash , Check , or CreditCard . |
body.PrintStatus | string | Optional | PrintStatus is applicable only for Check . Ignored for CreditCard charge or refund. Valid values: NotSet , NeedToPrint , PrintComplete. |
body.PrivateNote | string | Optional | User-entered, organization-private note about the transaction. This field maps to the Memo field on the Expense form in the QuickBooks UI. |
body.PurchaseEx | object | Optional | For internal use. Additional keys: allowed |
body.RecurDataRef | Model | Optional | Expand Create a purchase order — request body — body Ship To A reference to the Recurring Transaction. It captures what recurring transaction template the Purchase was created from. Read only: true |
body.RemitToAddr | Model | Optional | Expand Create a vendor — request body — body Bill Addr Address to which the payment should be sent. This attribute is applicable only for Check . Ignored for CreditCard charge or refund. If a physical address is updated from within the transaction object, the QuickBooks Online API flows individual address components differently into the Line elements of the transaction response then when the transaction was first created: Line1 and Line2 elements are populated with the customer name and company name. Original Line1 through Line 5 contents, City , SubDivisionCode , and PostalCode flow into Line3 through Line5 as a free format strings. Read only: true |
body.TotalAmt | JSON | Optional | Indicates the total amount of the transaction. This includes the total of all the charges, allowances, and taxes. Calculated by QuickBooks business logic; any value you supply is over-written by QuickBooks. Decimal string Read only: true |
body.TotalAmt (anyOf 1) | number | Alternative | |
body.TotalAmt (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:.[0-9]+)?$ |
body.TxnDate | string | Optional | The date entered by the user when this transaction occurred. For posting transactions, this is the posting date that affects the financial statements. If the date is not supplied, the current date on the server is used. Sort order is ASC by default. |
body.TxnSource | string | Optional | Used internally to specify originating source of a credit card transaction. |
body.TxnTaxDetail | Model | Optional | Expand Create a bill — request body — body Txn Tax Detail This data type provides information for taxes charged on the transaction as a whole. It captures the details sales taxes calculated for the transaction based on the tax codes referenced by the transaction. This can be calculated by QuickBooks business logic or you may supply it when adding a transaction. See Global tax model for more information about this element. If sales tax is disabled ( Preferences.TaxPrefs.UsingSalesTax is set to false ) then TxnTaxDetail is ignored and not stored. |
body.CustomField | array | Optional | One of, up to three custom fields for the transaction. Available for custom fields so configured for the company. Check Preferences.SalesFormsPrefs.CustomField and Preferences.VendorAndPurchasesPrefs.POCustomField for custom fields currenly configured. Click here to learn about managing custom fields. |
body.CustomField[] | Model | Each item | Expand Void an invoice — request body — body Custom Field item |
body.domain | string | Optional | |
body.sparse | boolean | Optional |
Referenced models: Read a bill — response body — Bill Meta Data, Create a vendor — request body — body Bill Addr, Create a bill — request body — body Line item, Create a bill — request body — body Currency Ref, Void an invoice — request body — body Custom Field item, Create a bill — request body — body Linked Txn item, Create a purchase order — request body — body Ship To, Create a bill — request body — body Txn Tax Detail
Response
Section titled “Response”Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
time | string | Optional | |
Purchase | Model | Optional | Expand Read a purchase — response body — Purchase |
Referenced models: Read a purchase — response body — Purchase
Schemas
Section titled “Schemas”18 more schemas are linked from the tables above, on the schema pages.
Read a bill — response body — Bill Meta Data
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
CreateTime | string | Optional | Time the entity was created in the source domain. Read only: true |
LastUpdatedTime | string | Optional | Time the entity was last updated in the source domain. Read only: true |
Create a vendor — request body — body Bill Addr
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
City | string | Optional | City name. |
Country | string | Optional | For international addresses, the request can be an ISO alpha-3 code or the full name of the country. The response for update and read operations returns ISO alpha-3 country codes only. |
CountrySubDivisionCode | string | Optional | Region within a country. For example, state name for USA, province name for Canada. |
Id | string | Optional | Unique identifier of the QuickBooks object for the address, autoincremented when the address is changed. This is an internal value included for backwards compatibility and can be ignored. Read only: true |
Line1 | string | Optional | First line of the address. |
Line2 | string | Optional | Second line of the address. |
Line3 | string | Optional | Third line of the address. |
Line4 | string | Optional | Fourth line of the address. |
Line5 | string | Optional | Fifth line of the address. |
PostalCode | string | Optional | Postal code. For example, zip code for USA and Canada |
Create a bill — request body — body Line item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
AccountBasedExpenseLineDetail | Model | Required within parent | Expand Create a bill — request body — body Line item Account Based Expense Line Detail LineDetail |
Amount | JSON | Required within parent | The amount of the line item. Decimal string |
Amount (anyOf 1) | number | Alternative | |
Amount (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?$ |
CustomExtensions | array | Optional | Array of custom extension objects that associate additional attributes with the line. The ExtensionType field specifies the type of extension. The currently supported value is DIMENSION . The AssociatedValues array contains key/value pairs referencing Dimensions DefinitionID/Dimension ValueID. Multiple key/value pairs per extension type are supported. This field is designed to support additional extension types in the future. Dimensions is available for Intuit Enterprise Suite. |
CustomExtensions[] | Model | Each item | Expand Create an item — request body — body Custom Extensions item |
Description | string | Optional | Free form text description of the line item that appears in the printed record. |
DetailType | string | Required within parent | Set to AccountBasedExpenseLineDetail for this type of line. |
Id | string | Optional | The Id of the line item. Its use in requests is as folllows: If Id is greater than zero and exists for the company, the request is considered an update operation for a line item. If no Id is provided, the Id provided is less than or equal to zero, or the Id provided is greater than zero and does not exist for the company then the request is considered a create operation for a line item. Available in all objects that use lines and support the update operation. Read only: true |
LineNum | JSON | Optional | Specifies the position of the line in the collection of transaction lines. Positive Integer. Decimal string |
LineNum (anyOf 1) | number | Alternative | |
LineNum (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?$ |
Referenced models: Create a bill — request body — body Line item Account Based Expense Line Detail, Create an item — request body — body Custom Extensions item
Create a bill — request body — body Currency Ref
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
name | string | Optional | The full name of the currency. |
value | JSON | Required within parent | |
value (anyOf 1) | string | Alternative | |
value (anyOf 2) | integer | Alternative | Minimum: 0 Maximum: 9007199254740991 |
Void an invoice — request body — body Custom Field item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
DefinitionId | string | Required within parent | Unique identifier of the CustomFieldDefinition that corresponds to this CustomField. Read only: true |
Name | string | Optional | Name of the custom field. Read only: true |
StringValue | string | Optional | The value for the StringType custom field. |
Type | string | Optional | Data type of custom field. Only one type is currently supported: StringType . Read only: true |
Create a bill — request body — body Linked Txn item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
TxnId | string | Required within parent | Transaction Id of the related transaction. |
TxnLineId | string | Optional | Required for Deposit and Bill entities. The line number of a specific line of the linked transaction. If supplied, the TxnId and TxnType attributes of the linked transaction must also be populated. Conditionally required |
TxnType | string | Required within parent | Transaction type of the linked object. |
Create a purchase order — request body — body Ship To
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
name | string | Optional | An identifying name for the object being referenced by value and is derived from the field that holds the common name of that object. This varies by context and specific type of object referenced. For example, references to a Customer object use Customer.DisplayName to populate this field. Optionally returned in responses, implementation dependent. |
value | JSON | Required within parent | |
value (anyOf 1) | string | Alternative | |
value (anyOf 2) | integer | Alternative | Minimum: 0 Maximum: 9007199254740991 |
Create a bill — request body — body Txn Tax Detail
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
TaxLine | array | Optional | |
TaxLine[] | Model | Each item | Expand Create a bill — request body — body Txn Tax Detail Tax Line item |
TotalTax | JSON | Optional | Total tax calculated for the transaction, excluding any tax lines manually inserted into the transaction line list. Decimal string |
TotalTax (anyOf 1) | number | Alternative | |
TotalTax (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?$ |
TxnTaxCodeRef | Model | Optional | Expand Create a purchase order — request body — body Ship To Reference to the transaction tax code. Query the TaxCode name list resource to determine the appropriate TaxCode object for this reference. Use TaxCode.Id and TaxCode.Name from that object for TaxCodeRef.value and TaxCodeRef.name , respectively. If specified and sales tax is disabled ( Preferences.TaxPrefs.UsingSalesTax is set to false ), this element is ignored and not returned. For sales transactions, only: if automated sales tax is enabled ( Preferences.TaxPrefs.PartnerTaxEnabled is set to true ) the supplied transaction tax code is replaced by the automated sales tax engine recommendation. |
Referenced models: Create a purchase order — request body — body Ship To, Create a bill — request body — body Txn Tax Detail Tax Line item
Read a bill — response body — Bill Currency Ref
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
name | string | Optional | The full name of the currency. |
value | JSON | Optional | |
value (anyOf 1) | string | Alternative | |
value (anyOf 2) | JSON | Alternative | |
value (anyOf 2) (anyOf 1) | integer | Alternative | |
value (anyOf 2) (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
Read an invoice — response body — Invoice Custom Field item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
DefinitionId | string | Optional | Unique identifier of the CustomFieldDefinition that corresponds to this CustomField. Read only: true |
Name | string | Optional | Name of the custom field. Read only: true |
StringValue | string | Optional | The value for the StringType custom field. |
Type | string | Optional | Data type of custom field. Only one type is currently supported: StringType . Read only: true |
Read a bill — response body — Bill Linked Txn item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: allowed |
TxnId | string | Optional | Transaction Id of the related transaction. |
TxnLineId | string | Optional | Required for Deposit and Bill entities. The line number of a specific line of the linked transaction. If supplied, the TxnId and TxnType attributes of the linked transaction must also be populated. Conditionally required |
TxnType | string | Optional | Transaction type of the linked object. |
Policy, approvals and errors
Section titled “Policy, approvals and errors”SDK function policy ID: quickbooks.purchase.create_a_purchase. Catalog operation: purchase/create_a_purchase. Rules can name either ID; function rules distinguish managed calls and conservatively cover raw calls sharing the route. Existing grant permissions and policy rules apply. wait() returns an immediate result or waits for a required approval; it never approves the request itself. Persist the approval ID to resume after a restart.
Provider errors retain their response; JSON decoding raises ProviderAPIError for provider failures. ManagedOperationError identifies contract/input/retention errors. See error handling and provider-specific behavior. Sensitive input may be refused before approval storage. A decoding error never resubmits a write.