auths
objectURL path where the file to download is located, without the filename.
Filename of the file to download.
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
const axios = require('axios')
if (!params.url_path || !params.target_download_filename) {
throw new Error("Must provide url_path, and target_download_filename parameters.");
}
const config = {
method: 'GET',
url: `${params.url_path}${params.target_download_filename}`,
responseType: 'arraybuffer',
}
const resp = await axios(config)
const fs = require("fs");
const buffer = Buffer.from(resp.data.toString('base64'), "base64");
fs.writeFileSync(`/tmp/${params.target_download_filename}`, buffer);
this.attachment_filename = params.target_download_filename;
Id of the organization tenant to use on the Xero Accounting API. See Get Tenant Connections for a workflow example on how to pull this data.
Name of the file to upload as an attachment to the Xero document.
Document type of where the attachment will be sent to. This is used in as part of the Xero Account API endpoint where the request is sent against.
Xero identifier of the document where the attachment will be sent to.
async
(params, auths) => {
}
//See the API docs: https://developer.xero.com/documentation/api/invoices#upload-attachment
//See a workflow example of this action: https://pipedream.com/@sergio/xero-accounting-api-upload-file-p_rvCqADQ/edit
if (!params.tenant_id) {
throw new Error("Must provide tenant_id parameter.");
}
//Creates a multipart/form-data object, adds file to upload
const FormData = require('form-data');
const fs = require("fs");
data = new FormData();
const file = fs.createReadStream(`/tmp/${params.attachment_filename}`);
data.append('file', file);
//Sends the request against Xero Accounting API
return await require("@pipedreamhq/platform").axios(this, {
method: "post",
url: `https://api.xero.com/api.xro/2.0/${params.document_type}/${params.document_id}/Attachments/${attachment_filename}`,
headers: {
Authorization: `Bearer ${auths.xero_accounting_api.oauth_access_token}`,
"xero-tenant-id": params.tenant_id
},
data
});