dontpanic
dontpanic2mo ago

Airtable "Create Records" API Error

I'm trying to use the Airtable "Create Records" API to add multiple records at once. I'm passing the following response from the OpenAI Assistant:
{
"response": "{\"fields\":[{\"Date\":\"2024-08-06\",\"Item\":\"Duck Eggs\",\"Quantity\":30,\"Unit\":\"unit\",\"Notes\":\"harvested\"},{\"Date\":\"2024-08-06\",\"Item\":\"Chicken Eggs\",\"Quantity\":10,\"Unit\":\"unit\",\"Notes\":\"harvested\"}]}"
}
{
"response": "{\"fields\":[{\"Date\":\"2024-08-06\",\"Item\":\"Duck Eggs\",\"Quantity\":30,\"Unit\":\"unit\",\"Notes\":\"harvested\"},{\"Date\":\"2024-08-06\",\"Item\":\"Chicken Eggs\",\"Quantity\":10,\"Unit\":\"unit\",\"Notes\":\"harvested\"}]}"
}
I need to format this correctly to be used by the Airtable API. I've added an empty node in between to format it correctly, and this is the output: [{"fields":{"Date":"2024-08-06","Item":"Duck Eggs","Quantity":30,"Unit":"unit","Notes":"harvested"}},{"fields":{"Date":"2024-08-06","Item":"Chicken Eggs","Quantity":10,"Unit":"unit","Notes":"harvested"}}] It is happening occasionally, but this is NOT happening consistently. Any suggestions to get the appropriate input every time?
1 Reply
AI Support
AI Support2mo ago
To use the Airtable "Create Records" API to add multiple records at once, you need to ensure that the JSON payload is correctly formatted. The payload should be an array of objects, where each object contains a fields property with the corresponding record data. Based on the response you provided from the OpenAI Assistant, it looks like the JSON needs to be correctly parsed and formatted. Here is a step-by-step guide to ensure you get the appropriate input consistently: 1. Parse the JSON Response: Ensure that the JSON response from the OpenAI Assistant is correctly parsed into a JavaScript object. 2. Format the Records: Create an array of objects where each object contains a fields property holding the record data. 3. Stringify the JSON: Convert the JavaScript object back to a JSON string before sending it to the Airtable API. Since you mentioned that the formatting is not happening consistently, you might want to double-check the steps where the JSON is being parsed and formatted. For more detailed information on how to use the Airtable "Create Records" API, please refer to the Airtable API documentation. If you continue experiencing issues, please submit your query via the in-app support button for further assistance.