Skip to main content

Purchase Transactions

This document provides an overview of the operations available for the Purchase Transactions business entity. Please note that the queries shown below only present a subset of the fields.

For a full list of fields, please refer to our schema documentation provided within our API. See Explore the API.

Mutations

Create Purchase Transactions

To create new Purchase transactions within a Financials or Dimensions database, the Purchase Transaction bulk create endpoint can be used. This operation supports both batching and posting of transactions. You can create one or more of the following types of Purchase transactions using this operation:

  • Purchase Invoice
  • Purchase Credit Note
  • Purchase Payment
  • Purchase Debit Adjustment
  • Purchase Credit Adjustment

Request

Here's an example of how you can use the create mutation:

mutation (
$transactions: [PurchaseTransactionBulkInput!]!
$validateOnly: Boolean
) {
creditors {
transactions {
bulkTransactions {
bulkCreate(transactions: $transactions, validateOnly: $validateOnly) {
... on IntEntityIds {
...IntEntityIdDetails
}
... on FailedValidation {
...FailedValidationDetails
}
... on UnexpectedError {
...UnexpectedErrorDetails
}
}
}
}
}
}

fragment IntEntityIdDetails on IntEntityIds {
ids
}

fragment FailedValidationDetails on FailedValidation {
errors {
...ValidationItemDetails
}
warnings {
...ValidationItemDetails
}
}

fragment ValidationItemDetails on ValidationItem {
message
details {
primaryKey
field
value
}
}

fragment UnexpectedErrorDetails on UnexpectedError {
errorMessage
}

When you execute the create mutation, it performs several steps to create new transactions:

  1. Running business validations: The API performs a number of business validations on the input data to ensure that it meets the required criteria. These validations can include checks for things like valid Supplier information, correct gross amount, and any other business rules specific to your application. If any validation errors occur, the mutation will return a response with the details of the errors.

  2. Calculating missing information: If any required information is missing from the input object, the mutation will calculate the missing values based on default settings or any other logic defined in the system. This ensures that the transaction has all the necessary data before it is created.

  3. Saving the transaction: If all the necessary information is present and the business validations pass successfully, the mutation will save the transaction in the system and make it available for further processing or retrieval.

Parameters

Transaction [Required]

This mutation requires an input object of type PurchaseTransactionBulkInput, which should contain all the necessary information to create the transaction.

Validate Only

This operation supports "validate only" mode by setting the validateOnly parameter to true. In this mode, the API will check your transaction against a number of business rules, but will not attempt to save the transaction to the database.

Response

After executing the create mutation, you will receive a response containing the IDs of the updated transactions if the creation was successful. If any validation errors or unexpected errors occur during the operation, the response will include the details of those errors.

An example of the three response types provided by this request can be found below:

{
"data": {
"creditors": {
"transactions": {
"bulkTransactions": {
"bulkCreate": {
[100, 101, 102]
}
}
}
}
}

Update Purchase Transactions

To update a Purchase transaction, you can use the bulk update mutation. Like the transaction creation request, this mutation requires an input object of type PurchaseTransactionBulkInput, which should contain the information you wish to update on the existing transaction.

note

It is only possible to update batched transactions via this operation.

Request

Here's an example of how you can use the update mutation to update a Purchase transaction:

mutation (
$transactions: [PurchaseTransactionBulkInput!]!
$validateOnly: Boolean
) {
creditors {
transactions {
bulkTransactions {
bulkUpdate(transactions: $transactions, validateOnly: $validateOnly) {
... on IntEntityIds {
...IntEntityIdDetails
}
... on FailedValidation {
...FailedValidationDetails
}
... on UnexpectedError {
...UnexpectedErrorDetails
}
}
}
}
}
}

fragment IntEntityIdDetails on IntEntityIds {
ids
}

fragment FailedValidationDetails on FailedValidation {
errors {
...ValidationItemDetails
}
warnings {
...ValidationItemDetails
}
}

fragment ValidationItemDetails on ValidationItem {
message
details {
primaryKey
field
value
}
}

fragment UnexpectedErrorDetails on UnexpectedError {
errorMessage
}

When you execute the update mutation, it performs the following steps to update the Purchase transaction:

  1. Finding the transaction: The mutation first finds the Purchase transaction in the system.
  2. Updating the information: The mutation then updates the transaction with the new information provided in the PurchaseTransactionInput object. You can modify any relevant fields such as Supplier information, transaction lines, or any other details specific to your application.
  3. Recalculating missing information: If any required information is missing from the input object, the mutation will calculate the missing values based on default settings or any other logic defined in the system. This ensures that the transaction has all the necessary data before it is created.
  4. Running business validations: Similar to the create mutation, the update mutation also performs business validations on the updated data to ensure it meets the required criteria. If any validation errors occur, the mutation will return a response with the details of the errors.
  5. Saving the updated transaction: If all the necessary information is present and the business validations pass successfully, the mutation will save the updated transaction in the system. This means that the changes will be persisted and available for further processing or retrieval.

Parameters

Transaction [Required]

This mutation requires an input object of type PurchaseTransactionBulkInput, which should contain all the necessary information to create the transaction.

Validate Only

This operation supports "validate only" mode by setting the validateOnly parameter to true, in this mode, the API will check your transaction against a number of business rules, but will not attempt to save the transaction to the database.

Response

After executing the update mutation, you will receive a response containing the updated Purchase transaction's ID if the update was successful. If any validation errors or unexpected errors occur during the operation, the response will include the details of those errors.

An example of the three response types provided by this request can be found below:

{
"data": {
"creditors": {
"transactions": {
"bulkTransactions": {
"bulkUpdate": {
[100,101,102]
}
}
}
}
}
}

Delete Purchase Transactions

To delete Purchase transactions, you can use the delete mutation. This operation contains a mandatory primaryKeys parameter which should be populated with the primary key of each transaction you want to delete.

note

Note this endpoint only supports the deletion of Purchase Transactions. For the removal of other transaction types, please refer to our API schema documentation: Explore the API

Here's an example of how you can use the delete mutation to delete Purchase transactions:

mutation ($primaryKeys: [Int!]!) {
creditors {
transactions {
batchedTransactions {
delete(primaryKeys: $primaryKeys) {
... on Succeeded {
...SucceededDetails
}
... on FailedValidation {
...FailedValidationDetails
}
... on UnexpectedError {
...UnexpectedErrorDetails
}
}
}
}
}
}

fragment SucceededDetails on Succeeded {
succeeded
}

fragment FailedValidationDetails on FailedValidation {
errors {
...ValidationItemDetails
}
warnings {
...ValidationItemDetails
}
}

fragment ValidationItemDetails on ValidationItem {
message
details {
primaryKey
field
value
}
}

fragment UnexpectedErrorDetails on UnexpectedError {
errorMessage
}

In the above example, you need to provide the primaryKeys array containing the primary keys of the transactions you want to delete. The mutation will then attempt to delete the specified transactions.

If the deletion is successful, the response will include a succeeded field with a value of true. If any validation errors occur during the deletion process, the response will include the details of those errors in the errors field. Additionally, if there are any warnings related to the deletion, they will be included in the warnings field. If an unexpected error occurs, the response will include an errorMessage field with the details of the error.

An example of the three response types provided by this request can be found below:

{
"data": {
"creditors": {
"transactions": {
"batchedTransactions": {
"delete": {
"succeeded"
}
}
}
}
}
}

Queries

Get Batched Purchase Transaction

To retrieve information about a specific batched Purchase transaction, you can use the transactionEntry\header query. This query requires an input parameter id which represents the primary key of the transaction you want to retrieve.

Here's an example of how you can use the transactionEntry\header query to get the details of a batched Purchase transaction:

query ($id: Int!) {
creditors {
transactions {
transactionEntry {
header(id: $id) {
transactionType
hasNextPage
header {
...HeaderDetails
}
detailLines {
...DetailLinesData
}
}
}
}
}
}

fragment HeaderDetails on PurchaseTransactionHeader {
primaryKey
headerReference
description
supplier {
code
name
anyCurrency
onStop
terms
taxRegistrationNumber
}
dates {
date
dueDate
anticipatedPaymentDate
}
values {
...TransactionValueData
}
period {
year
yearLabel
number
}
subLedger {
code
description
}
}

fragment DetailLinesData on PurchaseTransactionDetail {
primaryKey
detail
tax {
code
rate
type
}
values {
...TransactionValueData
}
costing {
project {
code
name
}
costCentre {
code
name
}
}
}

fragment TransactionValueData on TransactionValues {
net
tax
gross
currencyNet
currencyTax
currencyGross
}

In this query, you need to provide the id parameter with the primary key of the batched Purchase transaction you want to retrieve. The response will include detailed information about the transaction, including the transaction type, header details, Supplier information, dates, values, period, subledger details, and detail lines.

The query only returns first page of detail lines, to get additional pages please use transactionEntry/details.

query (
$filter: PurchaseTransactionDetailFilterInput!
$sort: [PurchaseTransactionDetailSortSortByInput!]
$first: Int
) {
creditors {
transactions {
transactionEntry {
details(filter: $filter, sort: $sort, first: $first) {
items {
primaryKey
detail
analysis {
code
name
nominalUpdate {
debit {
code
name
}
credit {
code
name
}
tax {
code
name
}
}
}
tax {
code
rate
type
}
values {
net
tax
gross
currencyNet
currencyTax
currencyGross
}
costing {
project {
code
name
}
costCentre {
code
name
}
}
accrual {
accrueOverPeriods
defer
account {
code
name
}
}
}
}
}
}
}
}

Query Transaction Headers

To retrieve information about transaction headers, you can use the allTransactions\header query. This query requires input parameters such as $first, $sort, $filter to specify the number of results, sorting criteria, and filtering conditions.

Filter options vary from field to field based on the type of the field, see PurchaseTransactionEnquiryFilterInput GraphQL type in API Reference.

Grouping by various columns is also possible. When a group column is specified, the result will be a unique list of values for the grouped column. It is possible to aggregate other columns as well by specifying $aggregate.

$fieldSelection is a parameter that can be used to specify which fields should be returned, it override the specification in the query. Fields selection can also be done through the query.

Here's an example of how you can use the header query to get transaction header details:

query (
$first: Int
$filter: PurchaseTransactionEnquiryHeaderFilterInput!
$sort: [PurchaseTransactionEnquiryHeaderSortSortByInput!]
$group: PurchaseTransactionEnquiryHeaderSort
$aggregate: PurchaseTransactionEnquiryHeaderSortGroupByInput
$fieldSelection: [PurchaseTransactionEnquiryHeaderSort]
) {
creditors {
transactions {
allTransactions {
header(
first: $first
sort: $sort
filter: $filter
group: $group
aggregate: $aggregate
fieldSelection: $fieldSelection
) {
items {
accountCode
accountName
date
periodNumber
orderNumber
transactionType
headerRef
batched
net
tax
description
gross
outstanding
reconciled
auditNo
yearLabel
dueDate
dateEntered
batchRef
headerRef
headerKey
exchangeRate
sortKey
anticipatedPaymentDate
currencyGross
currencyNet
currencyOutstanding
currencySymbol
currencyTax
onDispute
subLedger
lastUpdatedBy
lastUpdatedDateTime
postedBy
postedDateTime
createdBy
createdDateTime
}
}
}
}
}
}

In the above query, you can customize the parameters $first, $sort, and $filter to retrieve the desired number of results, apply sorting based on specific fields, and filter the transactions based on certain conditions.

The response will include an array of transaction headers, each containing various fields such as account code, account name, transaction date, etc.

Query Details

To retrieve detailed information about Purchase transactions, you can use the details field within the allTransactions query. This field requires the following input parameters:

  • $first: Specifies the maximum number of results to retrieve.
  • $sort: Specifies the sorting order for the results based on specific fields.
  • $filter: Specifies the conditions to filter the transactions.

Here's an example of how you can use the details field to retrieve detailed information about Purchase transactions:

query($first: Int, $sort: [PurchaseTransactionEnquiryDetailSortSortByInput!], $filter: PurchaseTransactionEnquiryDetailFilterInput!) {
creditors{
transactions{
allTransactions {
details (first: $first, sort: $sort, filter: $filter) {
items {
primaryKey
headerPrimary
analysisCode
analysisName
itemCode
projectCode
projectName
costCentreCode
costCentreName
orderNumber
net
taxCode
tax
gross
transactionAuditNumber
detail
costPrice
sellPrice
accountCode
accountName
currentSortKey
currencyGross
currencyNet
currencySymbol
currencyTax
dueDate
quantity
analysisType
}
}
}
}
}
}

In the above query, you can customize the parameters $first, $sort, and $filter to retrieve the desired number of results, apply sorting based on specific fields, and filter the transactions based on certain conditions.

The response will include an array of transaction details, each containing various fields such as primary key, analysis code, item code, net amount, tax amount, etc.