Hi there,
How can I get data from Airtable in JSON format so that I can run custom code from Zapier?
Best,
Nicholas
Hi there,
How can I get data from Airtable in JSON format so that I can run custom code from Zapier?
Best,
Nicholas
Hi
Good question.
Can you please elaborate about what you are trying to do in the Zap Code step with what data from Airtable?
Hi
I’m trying to pass a few payloads through some custom code. But I can’t get the payload to pass through from Airtable.
This is my code:
// Define the output variable
console.log(inputData)
let output;
// Set up variables for the Webflow API endpoint and the item you want to update
const endpoint = 'https://api.webflow.com/collections/{collection_id}/items/{item_id}';
const collectionId = '63e1bdb25639fe5b8188bb75';
const itemId = 'itemIDPayload';
// Set up the data you want to send in the PATCH request
const data = {
fields: {
// The name of the multi-reference field you want to update
'multi_reference_field': _
// The IDs of the items you want to reference in the multi-reference field
'wrappedAirtableItems'
],
// Set name, archived, and draft to false
'name': 'My New Name',
'_archived': false,
'_draft': false
}
};
// Set up the headers for the Webflow API request
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 6afb5041dadfb64aa2a34386c0ed5a7d2fdc4d5fd2c774bdc8aca9c80f005549',
'accept-version': '1.0.0'
};
// Send the PATCH request using the Fetch API with a callback function
fetch(endpoint.replace('{collection_id}', collectionId).replace('{item_id}', itemId), {
method: 'PATCH',
headers: headers,
body: JSON.stringify(data)
})
.then(res => res.json())
.then(json => {
console.log(json);
// Set the output data
output = {
id: json._id,
message: 'Item updated successfully'
};
})
.catch(err => console.error(err));
// Export the output variable
module.exports = {
output: output
};
Hi
Perhaps you can elaborate more about where you are getting stuck specifically.
You can use the Code step to take the variables from Airtable as Input Data, and map them to desired location in the JSON within the Code.
Help articles about using the Code app: https://zapier.com/apps/code/help
If you see seeking help, consider hiring a Certified Zapier Expert: https://zapier.com/experts/automation-ace
Hi
The data from the input section of the Code isn’t being passed through into the Javasscript properly. So I’m wondering if I should change my approach and extract the Airtable data as JSON structured.
Best,
Nicholas
Reference: https://help.zapier.com/hc/en-us/articles/8496197098253-JavaScript-code-examples-in-Zaps
In your JavaScript Code, I don’t see those variables being declared.
This page provides some examples for using JavaScript code steps. Every example depends on specific inputData
, which is provided under the "Input Data" field when setting up your Zap. This example screenshot shows three demonstration inputs you can use in your code like this: inputData.body
, inputData.receivedDate
, and inputData.subject
. Be sure you read the code examples and provide the right inputs otherwise nothing will work as expected!
Hi
Regards,
Hamish
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.