Hi! I’m not understanding how to upload a file (.png, .jpg or .pdf) to hubpost. How can I use this code without the axios?
import axios from "axios";
import { join } from "path";
import { createReadStream } from "fs";
import FormData from "form-data";
const HubspotAPI = axios.create({
baseURL: "https://api.hubapi.com",
headers: {
` Authorization: ```
}
});
try {
// Create and upload a new file
const formData = new FormData();
formData.append("file", createReadStream(join(__dirname, "cat.webp")));
formData.append("folderPath", "cats");
formData.append("options", JSON.stringify({
access: "PUBLIC_NOT_INDEXABLE",
overwrite: true
}))
const { data: { id: fileId } } = await HubspotAPI.post("/files/v3/files", formData)
// Send the file to a object
const { data: noteResponse } = await HubspotAPI.post("/engagements/v1/engagements", {
"engagement": {
"type": "NOTE",
},
"metadata": {
"body": "Arquivo enviado pelo CMS."
},
"associations": {
"contactIds": [5686102],
},
"attachments": [
{
"id": fileId
}
],
})
console.log(noteResponse)
} catch (error) {
console.log(error.response.data)
}