From your provided official document, I understood your question as follows.
You want to convert the following Node.js script to Google Apps Script.
const FormData = require('form-data');
const axios = require('axios');
const fs = require('fs');
const form = new FormData();
form.append('filename', '')
form.append('attachment', fs.createReadStream('./img.png'));
const headers = form.getHeaders();
headers.authorization = `Bearer ${your_api_token}`;
axios({
method: 'post',
url: 'https://api.clickup.com/api/v2/task/123/attachment',
data: form,
headers,
})
.then(() => console.log('success'))
.catch(() => console.log('fail'));In this case, how about the following modification?
From your showing script, I guessed "file" is Blob. Please be careful about this.
function addAttachment(taskId, file) {
// let bytes = file.getBytes(); // In this modification. "file" is directly used as a Blob. payload: { filename: "sample filename", attachment: file },
}
let response = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());
console.log(response);
}In the case of "multipart/form-data" with UrlFetchApp, it is not required to include "Content-Type" in the request header. The request body is automatically created by UrlFetchApp.
In this modification, the request of Google Apps Script is the same as that of Node.js. But, if an error occurs, please confirm your variables again. And, if the status code of 403 occurs, I'm worried that the API might not be able to be requested from the Google side.