Nov 03, 2022 02:26 AM
Hi, i got this error since 4 hours ago. Please help me identify what is the error.
let table = base.getTable(cursor.activeTableId)
let record = await input.recordAsync(‘Pick a record’, table)const { fields } = table;
// const sizes = record?.getCellValueAsString(“size”);
const sizes = “1080x1080”
// const template = record?.getCellValueAsString(“template”);
const template =“watermark-square-1”
// const API_KEY = record?.getCellValueAsString(“API Key”);
const API_KEY =“XXXXXXXXXXXXXX”// make sure there’s a record
if (record) {
const urls = record.getCellValue(“Foto”).map((row) => row.url);const promises = urls.map((url) => {
return new Promise(async (res, rej) => { // build an empty request var request = { template, "sizes": [], "elements": { "product": { url } } }; if (sizes) { const sizesParts = sizes.split(",").map((part) => part.trim()); sizesParts.forEach((size) => { const sizeParts = size.split("x").map((part) => part.trim()); request.sizes.push({ "width": parseInt(sizeParts[0]), "height": parseInt(sizeParts[1]) }); }); } fields.forEach((field) => { if (field.name.includes(":")) { // split and add to the elements object const parts = field.name.split(":"); const name = parts[0]; const property = parts[1]; if (!request.elements[name]) { request.elements[name] = {}; } request.elements[name][property] = record?.getCellValueAsString(field.name) } }) let response = await fetch('https://api.canvas.switchboard.ai', { method: 'POST', body: JSON.stringify(request), headers: { 'Content-Type': 'application/json', 'X-API-Key': API_KEY } }) try { let asJson = await response.json() if (record && asJson?.success) { const newResults = asJson.sizes.map((result) => { return { url: result.url }; }); res(newResults); } else { console.log(asJson); } } catch (err) { console.warn("Something went wrong"); console.error(err); } });
});
// run all the requests
const result = await Promise.all(promises);const updateData = result.flatMap((r) => r);
await table.updateRecordAsync(record.id, {
image: updateData
});console.log(“Done.”);
}
Nov 04, 2022 11:23 AM
…and the error was…?
Nov 04, 2022 07:41 PM
It works again. I don’t know why