Skip to content

17984 xero #18071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 20, 2025
Merged
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
import {
removeNullEntries,
formatLineItems,
removeNullEntries,
} from "../../common/util.mjs";
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";

export default {
key: "xero_accounting_api-add-line-item-to-invoice",
name: "Add Items to Existing Sales Invoice",
description: "Adds line items to an existing sales invoice. [See the docs here](https://developer.xero.com/documentation/api/accounting/invoices#post-invoices)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
xeroAccountingApi,
Expand All @@ -35,16 +35,15 @@ export default {
},
},
async run({ $ }) {
const {
tenantId,
invoiceId,
lineItems,
} = this;
const data = removeNullEntries({
InvoiceID: invoiceId,
LineItems: formatLineItems(lineItems),
const response = await this.xeroAccountingApi.createInvoice({
$,
tenantId: this.tenantId,
data: removeNullEntries({
InvoiceID: this.invoiceId,
LineItems: formatLineItems(this.lineItems),
}),
});
const response = await this.xeroAccountingApi.createInvoice($, tenantId, data);

response && $.export("$summary", "Line item created successfully");
return response;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
// legacy_hash_id: a_WYiwz2
import { axios } from "@pipedream/platform";
import { ConfigurationError } from "@pipedream/platform";
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";

export default {
key: "xero_accounting_api-create-bank-transaction",
name: "Create Bank Transaction",
version: "0.1.1",
description: "Create a new bank transaction [See the documentation](https://developer.xero.com/documentation/api/accounting/banktransactions#put-banktransactions)",
version: "0.1.2",
type: "action",
props: {
xero_accounting_api: {
type: "app",
app: "xero_accounting_api",
xeroAccountingApi,
tenantId: {
propDefinition: [
xeroAccountingApi,
"tenantId",
],
},
bank_account_code: {
bankAccountCode: {
type: "string",
label: "Bank account code",
description: "The Account Code of the Bank Account of the transaction. If Code is not included then AccountID is required.",
optional: true,
},
bank_account_id: {
bankAccountId: {
type: "string",
label: "Bank account ID",
description: "The ID of the Bank Account transaction. If AccountID is not included then Code is required.",
optional: true,
},
contact_id: {
contactId: {
type: "string",
label: "Contact ID",
description: "Id of the contact associated to the bank transaction.",
optional: true,
},
contact_name: {
contactName: {
type: "string",
label: "Contact name",
description: "Name of the contact associated to the bank transaction. If there is no contact matching this name, a new contact is created.",
optional: true,
},
tenant_id: {
type: "string",
description: "Id of the organization tenant to use on the Xero Accounting API. See [Get Tenant Connections](https://pipedream.com/@sergio/xero-accounting-api-get-tenant-connections-p_OKCzOgn/edit) for a workflow example on how to pull this data.",
},
type: {
type: "string",
label: "Type",
description: "See [Bank Transaction Types](https://developer.xero.com/documentation/api/types#BankTransactionTypes)",
options: [
"RECEIVE",
Expand All @@ -47,51 +52,60 @@ export default {
"SPEND-PREPAYMENT",
],
},
line_items: {
lineItems: {
type: "object",
label: "Line items",
description: "See [LineItems](https://developer.xero.com/documentation/api/banktransactions#LineItemsPOST). The LineItems element can contain any number of individual LineItem sub-elements. At least **one** is required to create a bank transaction.",
},
is_reonciled: {
isReconciled: {
type: "boolean",
label: "Is reconciled",
description: "Boolean to show if transaction is reconciled. Conversion related apps can set the IsReconciled flag in scenarios when a matching bank statement line is not available. [Learn more](http://help.xero.com/#Q_BankRecNoImport)",
optional: true,
},
date: {
type: "string",
label: "Date",
description: "Date of transaction - YYYY-MM-DD",
optional: true,
},
reference: {
type: "string",
label: "Reference",
description: "Reference for the transaction. Only supported for SPEND and RECEIVE transactions.",
optional: true,
},
currency_code: {
currencyCode: {
type: "string",
label: "Currency code",
description: "The currency that bank transaction has been raised in (see [Currencies](https://developer.xero.com/documentation/api/currencies)). Setting currency is only supported on overpayments.",
optional: true,
},
currency_rate: {
currencyRate: {
type: "string",
label: "Currency rate",
description: "Exchange rate to base currency when money is spent or received. e.g. 0.7500 Only used for bank transactions in non base currency. If this isn't specified for non base currency accounts then either the user-defined rate (preference) or the [XE.com day rate](http://help.xero.com/#CurrencySettings$Rates) will be used. Setting currency is only supported on overpayments.",
optional: true,
},
url: {
type: "string",
label: "URL",
description: "URL link to a source document - shown as \"Go to App Name\"",
optional: true,
},
status: {
type: "string",
label: "Status",
description: "See [Bank Transaction Status Codes](https://developer.xero.com/documentation/api/types#BankTransactionStatuses)",
optional: true,
options: [
"AUTHORISED",
"DELETED",
],
},
line_amount_types: {
lineAmountTypes: {
type: "string",
label: "Line amount types",
description: "Line amounts are exclusive of tax by default if you don't specify this element. See [Line Amount Types](https://developer.xero.com/documentation/api/types#LineAmountTypes)",
optional: true,
options: [
Expand All @@ -102,41 +116,39 @@ export default {
},
},
async run({ $ }) {
//See the API docs: https://developer.xero.com/documentation/api/banktransactions#PUT

if ((!this.bank_account_code && !this.bank_account_id)
|| (!this.contact_id && !this.contact_name)
|| !this.tenant_id || !this.type || !this.line_items) {
throw new Error("Must provide one of bank_account_code or bank_account_id, contact_id or contact_name, tenant_id, type, and line_items parameters.");
if (!this.bankAccountCode && !this.bankAccountId) {
throw new ConfigurationError("Must provide one of **Bank Account Code** or **Bank Account ID** parameters.");
}
if (!this.contactId && !this.contactName) {
throw new ConfigurationError("Must provide one of **Contact ID** or **Contact Name** parameters.");
}

return await axios($, {
method: "put",
url: "https://api.xero.com/api.xro/2.0/BankTransactions",
headers: {
"Authorization": `Bearer ${this.xero_accounting_api.$auth.oauth_access_token}`,
"xero-tenant-id": this.tenant_id,
},
const response = await this.xeroAccountingApi.createBankTransaction({
$,
tenantId: this.tenantId,
data: {
Type: this.type,
BankAccount: {
Code: this.bank_account_code,
AccountID: this.bank_account_id,
Code: this.bankAccountCode,
AccountID: this.bankAccountId,
},
Contact: {
ContactID: this.contact_id,
Name: this.contact_name,
ContactID: this.contactId,
Name: this.contactName,
},
IsReconciled: this.is_reonciled,
IsReconciled: this.isReconciled,
Date: this.date,
Reference: this.reference,
CurrencyCode: this.currency_code,
CurrencyRate: this.currency_rate,
CurrencyCode: this.currencyCode,
CurrencyRate: this.currencyRate,
Url: this.url,
Status: this.status,
Lineitems: this.line_items,
LineAmountTypes: this.line_amount_types,
Lineitems: this.lineItems,
LineAmountTypes: this.lineAmountTypes,
},
});

$.export("$summary", `Successfully created bank transaction with ID: ${response.BankTransactions[0].BankTransactionID}`);
return response;
},
};
53 changes: 23 additions & 30 deletions components/xero_accounting_api/actions/create-bill/create-bill.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
removeNullEntries,
deleteKeys,
isValidDate,
formatLineItems,
isValidDate,
removeNullEntries,
} from "../../common/util.mjs";
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";

export default {
key: "xero_accounting_api-create-bill",
name: "Create Bill",
description: "Creates a new bill (Accounts Payable)[See the docs here](https://developer.xero.com/documentation/api/accounting/invoices)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
xeroAccountingApi,
Expand Down Expand Up @@ -73,34 +73,27 @@ export default {
},
},
async run({ $ }) {
const {
tenantId,
contact,
invoiceNumber,
reference,
lineItems,
date,
dueDate,
currencyCode,
} = this;
const data = removeNullEntries({
Type: "ACCPAY",
Contact: contact?.ContactID
? deleteKeys(contact, [
"Name",
"FirstName",
"LastName",
"EmailAddress",
])
: contact,
LineItems: formatLineItems(lineItems),
Date: isValidDate(date, "Date") && date,
DueDate: isValidDate(dueDate, "DueDate") && dueDate,
CurrencyCode: currencyCode,
InvoiceNumber: invoiceNumber,
Reference: reference,
const response = await this.xeroAccountingApi.createInvoice({
$,
tenantId: this.tenantId,
data: removeNullEntries({
Type: "ACCPAY",
Contact: this.contact?.ContactID
? deleteKeys(this.contact, [
"Name",
"FirstName",
"LastName",
"EmailAddress",
])
: this.contact,
LineItems: formatLineItems(this.lineItems),
Date: isValidDate(this.date, "Date") && this.date,
DueDate: isValidDate(this.dueDate, "DueDate") && this.dueDate,
CurrencyCode: this.currencyCode,
InvoiceNumber: this.invoiceNumber,
Reference: this.reference,
}),
});
const response = await this.xeroAccountingApi.createInvoice($, tenantId, data);
response && $.export("$summary", "Bill successfully created");
return response;
},
Expand Down
Loading
Loading