Skip to content

Commit ef36669

Browse files
committed
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.
1 parent 906b647 commit ef36669

File tree

7 files changed

+76
-69
lines changed

7 files changed

+76
-69
lines changed

components/xero_accounting_api/actions/create-credit-note/create-credit-note.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ConfigurationError } from "@pipedream/platform";
2+
import { formatLineItems } from "../../common/util.mjs";
23
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
34

45
export default {
@@ -139,7 +140,7 @@ export default {
139140
Date: this.date,
140141
Status: this.status,
141142
LineAmountTypes: this.lineAmountTypes,
142-
LineItems: this.lineItems,
143+
LineItems: formatLineItems(this.lineItems),
143144
CurrencyCode: this.currencyCode,
144145
CreditNoteNumber: this.creditNoteNumber,
145146
Reference: this.reference,

components/xero_accounting_api/actions/make-an-api-call/make-an-api-call.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/util.mjs";
23
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
34

45
export default {
@@ -60,7 +61,8 @@ export default {
6061
method: this.requestMethod,
6162
path: this.relativeUrl,
6263
params: this.queryString,
63-
data: this.requestBody,
64+
headers: parseObject(this.headers),
65+
data: parseObject(this.requestBody),
6466
});
6567

6668
$.export("$summary", `Successfully made API call to ${this.relativeUrl}`);

components/xero_accounting_api/actions/xero-accounting-create-employee/xero-accounting-create-employee.mjs

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

45
export default {
@@ -53,9 +54,9 @@ export default {
5354
tenantId: this.tenantId,
5455
data: {
5556
Status: this.status,
56-
FirstName: this.first_name,
57-
LastName: this.last_name,
58-
ExternalLink: this.external_link,
57+
FirstName: this.firstName,
58+
LastName: this.lastName,
59+
ExternalLink: parseObject(this.externalLink),
5960
},
6061
});
6162

components/xero_accounting_api/actions/xero-accounting-create-or-update-contact/xero-accounting-create-or-update-contact.mjs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { parseObject } from "../../common/util.mjs";
12
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
23

34
export default {
@@ -194,32 +195,32 @@ export default {
194195
tenantId: this.tenantId,
195196
data: {
196197
Name: this.name,
197-
ContactID: this.contact_id,
198-
ContactNumber: this.contact_number,
199-
AccountNumber: this.account_number,
200-
ContactStatus: this.contact_status,
201-
FirstName: this.first_name,
202-
LastName: this.last_name,
203-
EmailAddress: this.email_address,
204-
SkypeUserName: this.skype_user_name,
205-
ContactPersons: this.contact_persons,
206-
BankAccountDetails: this.bank_account_details,
207-
TaxNumber: this.tax_number,
208-
AccountsReceivableTaxType: this.account_receivable_tax_type,
209-
AccountsPayableTaxType: this.account_payable_type,
210-
Addresses: this.addresses,
211-
Phones: this.phones,
212-
IsSupplier: this.is_supplier,
213-
IsCustomer: this.is_customer,
214-
DefaultCurrency: this.default_currency,
215-
XeroNetworkKey: this.xero_network_key,
216-
SalesDefaultAccountCode: this.sales_default_account_code,
217-
PurchasesDefaultAccountCode: this.puchases_default_account_code,
218-
SalesTrackingCategories: this.sales_tracking_categories,
219-
PurchasesTrackingCategories: this.puechases_tracking_categories,
220-
TrackingCategoryName: this.tracking_category_name,
221-
TrackingOptionName: this.tracking_option_name,
222-
PaymentTerms: this.payment_terms,
198+
ContactID: this.contactId,
199+
ContactNumber: this.contactNumber,
200+
AccountNumber: this.accountNumber,
201+
ContactStatus: this.contactStatus,
202+
FirstName: this.firstName,
203+
LastName: this.lastName,
204+
EmailAddress: this.emailAddress,
205+
SkypeUserName: this.skypeUserName,
206+
ContactPersons: parseObject(this.contactPersons),
207+
BankAccountDetails: this.bankAccountDetails,
208+
TaxNumber: this.taxNumber,
209+
AccountsReceivableTaxType: this.accountReceivableTaxType,
210+
AccountsPayableTaxType: this.accountPayableType,
211+
Addresses: parseObject(this.addresses),
212+
Phones: parseObject(this.phones),
213+
IsSupplier: this.isSupplier,
214+
IsCustomer: this.isCustomer,
215+
DefaultCurrency: this.defaultCurrency,
216+
XeroNetworkKey: this.xeroNetworkKey,
217+
SalesDefaultAccountCode: this.salesDefaultAccountCode,
218+
PurchasesDefaultAccountCode: this.puchasesDefaultAccountCode,
219+
SalesTrackingCategories: this.salesTrackingCategories,
220+
PurchasesTrackingCategories: this.puechasesTrackingCategories,
221+
TrackingCategoryName: this.trackingCategoryName,
222+
TrackingOptionName: this.trackingOptionName,
223+
PaymentTerms: this.paymentTerms,
223224
},
224225
});
225226

components/xero_accounting_api/actions/xero-accounting-update-contact/xero-accounting-update-contact.mjs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/util.mjs";
23
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
34

45
export default {
@@ -199,32 +200,32 @@ export default {
199200
contactId: this.contactId,
200201
data: {
201202
Name: this.name,
202-
ContactID: this.contact_id,
203-
ContactNumber: this.contact_number,
204-
AccountNumber: this.account_number,
205-
ContactStatus: this.contact_status,
206-
FirstName: this.first_name,
207-
LastName: this.last_name,
208-
EmailAddress: this.email_address,
209-
SkypeUserName: this.skype_user_name,
210-
ContactPersons: this.contact_persons,
211-
BankAccountDetails: this.bank_account_details,
212-
TaxNumber: this.tax_number,
213-
AccountsReceivableTaxType: this.account_receivable_tax_type,
214-
AccountsPayableTaxType: this.account_payable_type,
215-
Addresses: this.addresses,
216-
Phones: this.phones,
217-
IsSupplier: this.is_supplier,
218-
IsCustomer: this.is_customer,
219-
DefaultCurrency: this.default_currency,
220-
XeroNetworkKey: this.xero_network_key,
221-
SalesDefaultAccountCode: this.sales_default_account_code,
222-
PurchasesDefaultAccountCode: this.puchases_default_account_code,
223-
SalesTrackingCategories: this.sales_tracking_categories,
224-
PurchasesTrackingCategories: this.puechases_tracking_categories,
225-
TrackingCategoryName: this.tracking_category_name,
226-
TrackingOptionName: this.tracking_option_name,
227-
PaymentTerms: this.payment_terms,
203+
ContactID: this.contactId,
204+
ContactNumber: this.contactNumber,
205+
AccountNumber: this.accountNumber,
206+
ContactStatus: this.contactStatus,
207+
FirstName: this.firstName,
208+
LastName: this.lastName,
209+
EmailAddress: this.emailAddress,
210+
SkypeUserName: this.skypeUserName,
211+
ContactPersons: parseObject(this.contactPersons),
212+
BankAccountDetails: this.bankAccountDetails,
213+
TaxNumber: this.taxNumber,
214+
AccountsReceivableTaxType: this.accountReceivableTaxType,
215+
AccountsPayableTaxType: this.accountPayableType,
216+
Addresses: parseObject(this.addresses),
217+
Phones: parseObject(this.phones),
218+
IsSupplier: this.isSupplier,
219+
IsCustomer: this.isCustomer,
220+
DefaultCurrency: this.defaultCurrency,
221+
XeroNetworkKey: this.xeroNetworkKey,
222+
SalesDefaultAccountCode: this.salesDefaultAccountCode,
223+
PurchasesDefaultAccountCode: this.puchasesDefaultAccountCode,
224+
SalesTrackingCategories: this.salesTrackingCategories,
225+
PurchasesTrackingCategories: this.puechasesTrackingCategories,
226+
TrackingCategoryName: this.trackingCategoryName,
227+
TrackingOptionName: this.trackingOptionName,
228+
PaymentTerms: this.paymentTerms,
228229
},
229230
});
230231

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

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

45
export default {
@@ -116,22 +117,22 @@ export default {
116117
data: {
117118
Type: "ACCPAY", //ACCPAY = Purchase Bill
118119
Contact: {
119-
ContactID: this.contact_id,
120-
Name: this.contact_name,
120+
ContactID: this.contactId,
121+
Name: this.contactName,
121122
},
122-
LineItems: this.line_items,
123+
LineItems: formatLineItems(this.lineItems),
123124
Date: this.date,
124-
DueDate: this.due_date,
125-
LineAmountTypes: this.line_amount_type,
126-
InvoiceNumber: this.purchase_bill_number,
125+
DueDate: this.dueDate,
126+
LineAmountTypes: this.lineAmountType,
127+
InvoiceNumber: this.purchaseBillNumber,
127128
Reference: this.reference,
128-
BrandingThemeID: this.branding_theme_id,
129+
BrandingThemeID: this.brandingThemeId,
129130
Url: this.url,
130-
CurrencyCode: this.currency_code,
131-
CurrencyRate: this.currency_rate,
131+
CurrencyCode: this.currencyCode,
132+
CurrencyRate: this.currencyRate,
132133
Status: this.status,
133-
SentToContact: this.sent_to_contact,
134-
PlannedPaymentDate: this.planned_payment_date,
134+
SentToContact: this.sentToContact,
135+
PlannedPaymentDate: this.plannedPaymentDate,
135136
},
136137
});
137138

components/xero_accounting_api/actions/xero-create-sales-invoice/xero-create-sales-invoice.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "xero_accounting_api-xero-create-sales-invoice",
77
name: "Create Sales Invoice",
88
description: "Creates a new sales invoice. [See the documentation](https://developer.xero.com/documentation/api/invoices#post)",
9-
version: "0.3.2",
9+
version: "0.3.3",
1010
type: "action",
1111
props: {
1212
xero,

0 commit comments

Comments
 (0)