Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Oct 31, 2020 09:49 AM
Hi,
I’m getting an error when I try to use create a Javascript FormData object in preparation for posting to an API. I would have thought FormData would have been well supported.
console.log(`Hello, ${base.name}!`);
const endPoint = new URL('https://myserver.com/jsonAPI/');
const formData = new FormData();
formData.append("user", 'tom');
const response = await fetch(endPoint.toString(), {
method: "POST",
body: formData,
});
console.log(response)
Getting an error saying that FormData is not defined
Oct 25, 2021 09:50 AM
They mention in their docs that the FormData API is not available in Airtable Scripting: Airtable Scripting
Mar 08, 2024 07:22 AM
To use formData you can build the object yourself using:
let data = {
key1: 'value1',
key2: 'value2'
};
// Encoder les paramètres en format x-www-form-urlencoded
let formData = Object.keys(data).map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key])).join('&');
await fetch('URL_DE_VOTRE_API', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: formData
});