Skip to content

Commit 9f56035

Browse files
17984 xero (#18071)
* Update Xero Accounting API components and actions, including version bumps and new features. Key changes include: - Bumped version to 0.4.0 for the Xero Accounting API package. - Added new actions for creating, updating, and deleting tracking categories and options. - Enhanced existing actions with improved error handling and response formatting. - Refactored code for better readability and maintainability, including consistent use of the xeroAccountingApi instance. - Updated utility functions and constants for better modularity. This update improves the overall functionality and usability of the Xero Accounting API integration. * pnpm update * pnpm update * Refactor Xero Accounting API actions to utilize utility functions for improved data handling. Key changes include: - Integrated `formatLineItems` in `create-credit-note` and `create-purchase-bill` actions. - Implemented `parseObject` in `make-an-api-call`, `create-employee`, `create-or-update-contact`, and `update-contact` actions for better object parsing. - Updated property names for consistency across actions. These enhancements improve code maintainability and ensure consistent data formatting across API interactions. * Refactor API request handling in Xero Accounting API. Changed the `make-an-api-call` method to directly return the axios call, simplifying the code and improving readability by removing unnecessary variable assignments. * remove console.log * Refactor Xero Accounting API actions for improved error handling and consistency. Key changes include: - Updated API request methods to use consistent casing for paths (e.g., `/Contacts` and `/Invoices`). - Enhanced error handling in actions to provide clearer feedback when no results are found. - Removed deprecated `find-contact` action and streamlined contact-related actions. - Bumped versions for several actions to reflect updates and improvements. These changes enhance the reliability and maintainability of the Xero Accounting API integration. * Refactor Xero Accounting API actions for consistency and clarity. Key changes include: - Updated `listInvoices`, `listManualJournals`, `listCreditNotes`, and `listContacts` methods to use `modifiedSince` instead of `modifiedAfter` for parameter naming consistency. - Simplified API request paths for `listInvoices` and `listManualJournals` by removing unnecessary identifiers. These modifications enhance the clarity and maintainability of the API integration. * Update components/xero_accounting_api/actions/list-invoices/list-invoices.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent b654775 commit 9f56035

File tree

46 files changed

+1867
-1322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1867
-1322
lines changed

components/xero_accounting_api/actions/add-line-item-to-invoice/add-line-item-to-invoice.mjs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
21
import {
3-
removeNullEntries,
42
formatLineItems,
3+
removeNullEntries,
54
} from "../../common/util.mjs";
5+
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
66

77
export default {
88
key: "xero_accounting_api-add-line-item-to-invoice",
99
name: "Add Items to Existing Sales Invoice",
1010
description: "Adds line items to an existing sales invoice. [See the docs here](https://developer.xero.com/documentation/api/accounting/invoices#post-invoices)",
11-
version: "0.0.2",
11+
version: "0.0.3",
1212
type: "action",
1313
props: {
1414
xeroAccountingApi,
@@ -35,16 +35,15 @@ export default {
3535
},
3636
},
3737
async run({ $ }) {
38-
const {
39-
tenantId,
40-
invoiceId,
41-
lineItems,
42-
} = this;
43-
const data = removeNullEntries({
44-
InvoiceID: invoiceId,
45-
LineItems: formatLineItems(lineItems),
38+
const response = await this.xeroAccountingApi.createInvoice({
39+
$,
40+
tenantId: this.tenantId,
41+
data: removeNullEntries({
42+
InvoiceID: this.invoiceId,
43+
LineItems: formatLineItems(this.lineItems),
44+
}),
4645
});
47-
const response = await this.xeroAccountingApi.createInvoice($, tenantId, data);
46+
4847
response && $.export("$summary", "Line item created successfully");
4948
return response;
5049
},
Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
1-
// legacy_hash_id: a_WYiwz2
2-
import { axios } from "@pipedream/platform";
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
33

44
export default {
55
key: "xero_accounting_api-create-bank-transaction",
66
name: "Create Bank Transaction",
7-
version: "0.1.1",
7+
description: "Create a new bank transaction [See the documentation](https://developer.xero.com/documentation/api/accounting/banktransactions#put-banktransactions)",
8+
version: "0.1.2",
89
type: "action",
910
props: {
10-
xero_accounting_api: {
11-
type: "app",
12-
app: "xero_accounting_api",
11+
xeroAccountingApi,
12+
tenantId: {
13+
propDefinition: [
14+
xeroAccountingApi,
15+
"tenantId",
16+
],
1317
},
14-
bank_account_code: {
18+
bankAccountCode: {
1519
type: "string",
20+
label: "Bank account code",
1621
description: "The Account Code of the Bank Account of the transaction. If Code is not included then AccountID is required.",
1722
optional: true,
1823
},
19-
bank_account_id: {
24+
bankAccountId: {
2025
type: "string",
26+
label: "Bank account ID",
2127
description: "The ID of the Bank Account transaction. If AccountID is not included then Code is required.",
2228
optional: true,
2329
},
24-
contact_id: {
30+
contactId: {
2531
type: "string",
32+
label: "Contact ID",
2633
description: "Id of the contact associated to the bank transaction.",
2734
optional: true,
2835
},
29-
contact_name: {
36+
contactName: {
3037
type: "string",
38+
label: "Contact name",
3139
description: "Name of the contact associated to the bank transaction. If there is no contact matching this name, a new contact is created.",
3240
optional: true,
3341
},
34-
tenant_id: {
35-
type: "string",
36-
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.",
37-
},
3842
type: {
3943
type: "string",
44+
label: "Type",
4045
description: "See [Bank Transaction Types](https://developer.xero.com/documentation/api/types#BankTransactionTypes)",
4146
options: [
4247
"RECEIVE",
@@ -47,51 +52,60 @@ export default {
4752
"SPEND-PREPAYMENT",
4853
],
4954
},
50-
line_items: {
55+
lineItems: {
5156
type: "object",
57+
label: "Line items",
5258
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.",
5359
},
54-
is_reonciled: {
60+
isReconciled: {
5561
type: "boolean",
62+
label: "Is reconciled",
5663
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)",
5764
optional: true,
5865
},
5966
date: {
6067
type: "string",
68+
label: "Date",
6169
description: "Date of transaction - YYYY-MM-DD",
6270
optional: true,
6371
},
6472
reference: {
6573
type: "string",
74+
label: "Reference",
6675
description: "Reference for the transaction. Only supported for SPEND and RECEIVE transactions.",
6776
optional: true,
6877
},
69-
currency_code: {
78+
currencyCode: {
7079
type: "string",
80+
label: "Currency code",
7181
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.",
7282
optional: true,
7383
},
74-
currency_rate: {
84+
currencyRate: {
7585
type: "string",
86+
label: "Currency rate",
7687
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.",
7788
optional: true,
7889
},
7990
url: {
8091
type: "string",
92+
label: "URL",
8193
description: "URL link to a source document - shown as \"Go to App Name\"",
8294
optional: true,
8395
},
8496
status: {
8597
type: "string",
98+
label: "Status",
8699
description: "See [Bank Transaction Status Codes](https://developer.xero.com/documentation/api/types#BankTransactionStatuses)",
87100
optional: true,
88101
options: [
89102
"AUTHORISED",
90103
"DELETED",
91104
],
92105
},
93-
line_amount_types: {
106+
lineAmountTypes: {
94107
type: "string",
108+
label: "Line amount types",
95109
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)",
96110
optional: true,
97111
options: [
@@ -102,41 +116,39 @@ export default {
102116
},
103117
},
104118
async run({ $ }) {
105-
//See the API docs: https://developer.xero.com/documentation/api/banktransactions#PUT
106-
107-
if ((!this.bank_account_code && !this.bank_account_id)
108-
|| (!this.contact_id && !this.contact_name)
109-
|| !this.tenant_id || !this.type || !this.line_items) {
110-
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.");
119+
if (!this.bankAccountCode && !this.bankAccountId) {
120+
throw new ConfigurationError("Must provide one of **Bank Account Code** or **Bank Account ID** parameters.");
121+
}
122+
if (!this.contactId && !this.contactName) {
123+
throw new ConfigurationError("Must provide one of **Contact ID** or **Contact Name** parameters.");
111124
}
112125

113-
return await axios($, {
114-
method: "put",
115-
url: "https://api.xero.com/api.xro/2.0/BankTransactions",
116-
headers: {
117-
"Authorization": `Bearer ${this.xero_accounting_api.$auth.oauth_access_token}`,
118-
"xero-tenant-id": this.tenant_id,
119-
},
126+
const response = await this.xeroAccountingApi.createBankTransaction({
127+
$,
128+
tenantId: this.tenantId,
120129
data: {
121130
Type: this.type,
122131
BankAccount: {
123-
Code: this.bank_account_code,
124-
AccountID: this.bank_account_id,
132+
Code: this.bankAccountCode,
133+
AccountID: this.bankAccountId,
125134
},
126135
Contact: {
127-
ContactID: this.contact_id,
128-
Name: this.contact_name,
136+
ContactID: this.contactId,
137+
Name: this.contactName,
129138
},
130-
IsReconciled: this.is_reonciled,
139+
IsReconciled: this.isReconciled,
131140
Date: this.date,
132141
Reference: this.reference,
133-
CurrencyCode: this.currency_code,
134-
CurrencyRate: this.currency_rate,
142+
CurrencyCode: this.currencyCode,
143+
CurrencyRate: this.currencyRate,
135144
Url: this.url,
136145
Status: this.status,
137-
Lineitems: this.line_items,
138-
LineAmountTypes: this.line_amount_types,
146+
Lineitems: this.lineItems,
147+
LineAmountTypes: this.lineAmountTypes,
139148
},
140149
});
150+
151+
$.export("$summary", `Successfully created bank transaction with ID: ${response.BankTransactions[0].BankTransactionID}`);
152+
return response;
141153
},
142154
};

components/xero_accounting_api/actions/create-bill/create-bill.mjs

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {
2-
removeNullEntries,
32
deleteKeys,
4-
isValidDate,
53
formatLineItems,
4+
isValidDate,
5+
removeNullEntries,
66
} from "../../common/util.mjs";
77
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
88

99
export default {
1010
key: "xero_accounting_api-create-bill",
1111
name: "Create Bill",
1212
description: "Creates a new bill (Accounts Payable)[See the docs here](https://developer.xero.com/documentation/api/accounting/invoices)",
13-
version: "0.0.2",
13+
version: "0.0.3",
1414
type: "action",
1515
props: {
1616
xeroAccountingApi,
@@ -73,34 +73,27 @@ export default {
7373
},
7474
},
7575
async run({ $ }) {
76-
const {
77-
tenantId,
78-
contact,
79-
invoiceNumber,
80-
reference,
81-
lineItems,
82-
date,
83-
dueDate,
84-
currencyCode,
85-
} = this;
86-
const data = removeNullEntries({
87-
Type: "ACCPAY",
88-
Contact: contact?.ContactID
89-
? deleteKeys(contact, [
90-
"Name",
91-
"FirstName",
92-
"LastName",
93-
"EmailAddress",
94-
])
95-
: contact,
96-
LineItems: formatLineItems(lineItems),
97-
Date: isValidDate(date, "Date") && date,
98-
DueDate: isValidDate(dueDate, "DueDate") && dueDate,
99-
CurrencyCode: currencyCode,
100-
InvoiceNumber: invoiceNumber,
101-
Reference: reference,
76+
const response = await this.xeroAccountingApi.createInvoice({
77+
$,
78+
tenantId: this.tenantId,
79+
data: removeNullEntries({
80+
Type: "ACCPAY",
81+
Contact: this.contact?.ContactID
82+
? deleteKeys(this.contact, [
83+
"Name",
84+
"FirstName",
85+
"LastName",
86+
"EmailAddress",
87+
])
88+
: this.contact,
89+
LineItems: formatLineItems(this.lineItems),
90+
Date: isValidDate(this.date, "Date") && this.date,
91+
DueDate: isValidDate(this.dueDate, "DueDate") && this.dueDate,
92+
CurrencyCode: this.currencyCode,
93+
InvoiceNumber: this.invoiceNumber,
94+
Reference: this.reference,
95+
}),
10296
});
103-
const response = await this.xeroAccountingApi.createInvoice($, tenantId, data);
10497
response && $.export("$summary", "Bill successfully created");
10598
return response;
10699
},

0 commit comments

Comments
 (0)