Skip to content

Commit 398aec8

Browse files
committed
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.
1 parent 4a2a9a6 commit 398aec8

File tree

21 files changed

+335
-515
lines changed

21 files changed

+335
-515
lines changed

components/xero_accounting_api/actions/create-bank-transaction/create-bank-transaction.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ export default {
116116
},
117117
},
118118
async run({ $ }) {
119-
if ((!this.bankAccountCode && !this.bankAccountId)
120-
|| (!this.contactId && !this.contactName)
121-
|| !this.tenantId || !this.type || !this.lineItems) {
122-
throw new ConfigurationError("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.");
123124
}
124125

125126
const response = await this.xeroAccountingApi.createBankTransaction({

components/xero_accounting_api/actions/create-tracking-category/create-tracking-category.mjs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@ export default {
3838
},
3939
});
4040

41-
const parsedOptions = parseObject(this.options);
41+
if (this.options) {
42+
const parsedOptions = parseObject(this.options);
4243

43-
for (const option of parsedOptions) {
44-
const optionResponse = await this.xeroAccountingApi.createTrackingOption({
45-
$,
46-
tenantId: this.tenantId,
47-
trackingCategoryId: response.TrackingCategories[0].TrackingCategoryID,
48-
data: {
49-
Name: option,
50-
},
51-
});
52-
response.TrackingCategories[0].Options.push(optionResponse.Options[0]);
44+
for (const option of parsedOptions) {
45+
const optionResponse = await this.xeroAccountingApi.createTrackingOption({
46+
$,
47+
tenantId: this.tenantId,
48+
trackingCategoryId: response.TrackingCategories[0].TrackingCategoryID,
49+
data: {
50+
Name: option,
51+
},
52+
});
53+
response.TrackingCategories[0].Options.push(optionResponse.Options[0]);
54+
}
5355
}
5456

5557
$.export("$summary", `Successfully created tracking category with ID: ${response.TrackingCategories[0].TrackingCategoryID}`);

components/xero_accounting_api/actions/create-update-contact/create-update-contact.mjs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { ConfigurationError } from "@pipedream/platform";
12
import { removeNullEntries } from "../../common/util.mjs";
23
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
34

45
export default {
56
key: "xero_accounting_api-create-update-contact",
67
name: "Create or update contact ",
78
description: "Creates a new contact or updates a contact if a contact already exists. [See the docs here](https://developer.xero.com/documentation/api/accounting/contacts)",
8-
version: "0.0.3",
9+
version: "0.1.0",
910
type: "action",
1011
props: {
1112
xeroAccountingApi,
@@ -15,15 +16,11 @@ export default {
1516
"tenantId",
1617
],
1718
},
18-
actionType: {
19-
label: "Type of action",
20-
description: "This triggers an update if UPDATE is selected",
19+
contactID: {
2120
type: "string",
22-
options: [
23-
"NEW",
24-
"UPDATE",
25-
],
26-
reloadProps: true,
21+
label: "Contact ID",
22+
description: "ID of the contact that requires update.",
23+
optional: true,
2724
},
2825
name: {
2926
type: "string",
@@ -68,18 +65,10 @@ export default {
6865
default: "ACTIVE",
6966
},
7067
},
71-
async additionalProps() {
72-
const props = {};
73-
if (this.actionType === "UPDATE") {
74-
props.contactID = {
75-
type: "string",
76-
label: "Contact ID",
77-
description: "ID of the contact that requires update.",
78-
};
79-
}
80-
return props;
81-
},
8268
async run({ $ }) {
69+
if (!this.contactID && !this.name) {
70+
throw new ConfigurationError("Must provide **Contact ID** or **Contact Name** parameter.");
71+
}
8372
const {
8473
contactID,
8574
tenantId,
@@ -99,7 +88,7 @@ export default {
9988
ContactStatus: contactStatus,
10089
});
10190
contactID && (data.ContactID = contactID);
102-
const response = await this.xeroAccountingApi.createContact({
91+
const response = await this.xeroAccountingApi.createOrUpdateContact({
10392
$,
10493
tenantId,
10594
data,

components/xero_accounting_api/actions/download-invoice/download-invoice.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export default {
3737
tenantId: this.tenantId,
3838
invoiceId: this.invoiceId,
3939
responseType: "arraybuffer",
40+
headers: {
41+
Accept: "application/pdf",
42+
},
4043
});
4144

4245
const invoicePdf = data.toString("base64");

components/xero_accounting_api/actions/find-contact/find-contact.mjs

Lines changed: 0 additions & 142 deletions
This file was deleted.

0 commit comments

Comments
 (0)