Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions components/xero_accounting_api/actions/delete-file/delete-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";

export default {
key: "xero_accounting_api-delete-file",
name: "Delete File",
description: "Delete a file. [See the documentation](https://developer.xero.com/documentation/api/files/files#delete-files)",
version: "0.0.{{ts}}",
type: "action",
props: {
xeroAccountingApi,
fileId: {
propDefinition: [
xeroAccountingApi,
"fileId",
],
},
},
async run({ $ }) {
const response = await this.xeroAccountingApi.deleteFile({
$,
fileId: this.fileId,
});
$.export("$summary", `Successfully deleted file with ID: ${this.fileId}`);
return response;
},
};
65 changes: 65 additions & 0 deletions components/xero_accounting_api/actions/list-files/list-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";

export default {
key: "xero_accounting_api-list-files",
name: "List Files",
description: "List files. [See the documentation](https://developer.xero.com/documentation/api/files/files#get-files)",
version: "0.0.{{ts}}",
type: "action",
props: {
xeroAccountingApi,
pagesize: {
type: "integer",
label: "Page Size",
description: "The number of records returned within a single API call",
optional: true,
default: 100,
min: 1,
max: 100,
},
page: {
type: "integer",
label: "Page",
description: "The page number of the current page in the returned records",
optional: true,
default: 1,
},
sort: {
type: "string",
label: "Sort",
description: "The field to sort the records by",
optional: true,
options: [
"Name",
"Size",
"CreatedDateUTC",
],
},
direction: {
type: "string",
label: "Direction",
description: "The direction to sort the records by",
optional: true,
options: [
"ASC",
"DESC",
],
},
},
async run({ $ }) {
const { Items: items } = await this.xeroAccountingApi.listFiles({
$,
params: {
pageSize: this.pagesize,
page: this.page,
sort: this.sort,
direction: this.direction,
},
});

$.export("$summary", `Successfully retrieved ${items.length} file${items.length === 1
? ""
: "s"}`);
return items;
},
};
42 changes: 42 additions & 0 deletions components/xero_accounting_api/actions/update-file/update-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";

export default {
key: "xero_accounting_api-update-file",
name: "Update File",
description: "Rename a file or move it to a different folder. [See the documentation](https://developer.xero.com/documentation/api/files/files#put-files)",
version: "0.0.{{ts}}",
type: "action",
props: {
xeroAccountingApi,
fileId: {
propDefinition: [
xeroAccountingApi,
"fileId",
],
},
name: {
type: "string",
label: "Name",
description: "The new name of the file",
optional: true,
},
folderId: {
propDefinition: [
xeroAccountingApi,
"folderId",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.xeroAccountingApi.updateFile(this.fileId, {
$,
data: {
Name: this.name,
FolderId: this.folderId,
},
});
$.export("$summary", `Successfully updated file with ID: ${this.fileId}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
import { getFileStreamAndMetadata } from "@pipedream/platform";
import FormData from "form-data";

export default {
key: "xero_accounting_api-upload-file-to-folder",
name: "Upload File to Folder",
description: "Upload a file to a folder. [See the documentation](https://developer.xero.com/documentation/api/files/files#post-files)",
version: "0.0.{{ts}}",
type: "action",
props: {
xeroAccountingApi,
filePathOrUrl: {
type: "string",
label: "File Path or URL",
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
},
folderId: {
propDefinition: [
xeroAccountingApi,
"folderId",
],
},
syncDir: {
type: "dir",
accessMode: "read",
sync: true,
optional: true,
},
},
async run({ $ }) {
const {
stream, metadata,
} = await getFileStreamAndMetadata(this.filePathOrUrl);

const data = new FormData();
data.append("Xero", stream, {
contentType: metadata.contentType,
knownLength: metadata.size,
filename: metadata.name,
});

const response = await this.xeroAccountingApi.uploadFileToFolder({
$,
folderId: this.folderId,
data,
headers: data.getHeaders(),
});

$.export("$summary", `Successfully uploaded file to folder with ID: ${this.folderId}`);
return response;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import xeroAccountingApi from "../../xero_accounting_api.app.mjs";

export default {
key: "xero_accounting_api-upload-file",
name: "Upload File",
name: "Upload File (Attachment)",
description: "Uploads a file to the specified document. [See the documentation](https://developer.xero.com/documentation/api/accounting/invoices#upload-attachment)",
version: "1.0.2",
version: "1.0.3",
type: "action",
props: {
xeroAccountingApi,
Expand Down Expand Up @@ -64,7 +64,7 @@ export default {
} = await getFileStreamAndMetadata(this.filePathOrUrl);
const fileBinary = await this.streamToBuffer(stream);

const response = await this.xeroAccountingApi.uploadFile({
const response = await this.xeroAccountingApi.uploadAttachment({
$,
tenantId: this.tenantId,
documentType: this.documentType,
Expand Down
3 changes: 2 additions & 1 deletion components/xero_accounting_api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"homepage": "https://pipedream.com/apps/xero_accounting_api",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"dependencies": {
"@pipedream/platform": "^3.1.0"
"@pipedream/platform": "^3.1.0",
"form-data": "^4.0.4"
},
"publishConfig": {
"access": "public"
Expand Down
83 changes: 81 additions & 2 deletions components/xero_accounting_api/xero_accounting_api.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,38 @@ export default {
label: "Line items",
description: "The LineItems collection can contain any number of individual LineItem sub-elements. At least one is required to create a complete Invoice. [Refer to Tax Type](https://developer.xero.com/documentation/api/accounting/types#report-tax-types), [Refer to Line Items](https://developer.xero.com/documentation/api/accounting/invoices#creating-updating-and-deleting-line-items-when-updating-invoices)\n\n**Example:** `[{\"Description\":\"Football\", \"Quantity\":\"20\", \"UnitAmount\":\"50000\", \"TaxType\":\"OUTPUT\" }]`",
},
fileId: {
type: "string",
label: "File ID",
description: "Unique identification of the file",
async options({ page }) {
const { Items: items } = await this.listFiles({
params: {
page: page + 1,
},
});
return items?.map(({
Id: value, Name: label,
}) => ({
label,
value,
})) || [];
},
},
folderId: {
type: "string",
label: "Folder ID",
description: "Unique identification of the folder",
async options() {
const folders = await this.listFolders();
return folders?.map(({
Id: value, Name: label,
}) => ({
label,
value,
})) || [];
},
},
},
methods: {
setLastDateChecked(db, value) {
Expand All @@ -102,10 +134,13 @@ export default {
modifiedSince,
path,
headers,
isFilesApi = false,
...opts
}) {
return axios($, {
url: `${BASE_URL}/api.xro/2.0${path}`,
url: `${BASE_URL}${(isFilesApi
? "/files.xro/1.0"
: "/api.xro/2.0")}${path}`,
headers: this.getHeader({
tenantId,
modifiedSince,
Expand Down Expand Up @@ -356,7 +391,7 @@ export default {
...opts,
});
},
uploadFile({
uploadAttachment({
documentType, documentId, fileName, ...opts
}) {
return this._makeRequest({
Expand Down Expand Up @@ -388,5 +423,49 @@ export default {
...opts,
});
},
listFiles(opts = {}) {
return this._makeRequest({
path: "/Files",
isFilesApi: true,
...opts,
});
},
uploadFileToFolder({
folderId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/Files/${folderId}`,
isFilesApi: true,
...opts,
});
},
updateFile({
fileId, ...opts
}) {
return this._makeRequest({
method: "PUT",
path: `/Files/${fileId}`,
isFilesApi: true,
...opts,
});
},
deleteFile({
fileId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/Files/${fileId}`,
isFilesApi: true,
...opts,
});
},
listFolders(opts = {}) {
return this._makeRequest({
path: "/Folders",
isFilesApi: true,
...opts,
});
},
},
};
17 changes: 9 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading