I’m not sure what I’m doing wrong. I’m using pipedream to connect to the Square API and using node.js I have this code:
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
square: {
type: "app",
app: "square",
}
},
async run({ steps, $ }) {
const Cover = steps.trigger.event.fields.Cover[0];
const imageUrl = Cover.url;
const filename = Cover.filename;
try {
const id = await createCatalogImage(imageUrl, filename);
console.log(`Created image with ID: ${id}`);
return id;
} catch (error) {
console.log(error);
throw Error(error);
}
}
});
async function createCatalogImage(imageUrl, filename) {
try {
const response = await axios(imageUrl, { responseType: 'blob' });
const image = response.data;
console.log(imageUrl);
console.log(filename);
let formData = new FormData();
formData.append("image", image, filename);
formData.append(
"request",
JSON.stringify({
idempotency_key: "fegte-98475",
is_primary: true,
image: {
type: "IMAGE",
id: "#1",
image_data: {
name: filename,
caption: filename,
},
},
})
);
const createCatalogImgPath = `https://connect.squareup.com/v2/catalog/images`;
const token = this.square.$auth.oauth_access_token;
const newCatalogImage = await makeRequest(
createCatalogImgPath,
"POST",
token,
formData,
{
url: createCatalogImgPath,
headers: {
Authorization: `Bearer ${token}`,
},
}
);
return newCatalogImage.image.id;
} catch (error) {
console.log(error);
throw Error(error);
}
}
and I'm getting this error:
Error
Error: TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined