Skip to main content
Question

Error: Request parameters failed validation.

  • March 27, 2025
  • 1 reply
  • 22 views

Forum|alt.badge.img+1

Hi Everyone - I am very new to API development and coding all together. I need some help with a script I am trying to implement. I keep getting this error thrown Error: Request parameters failed validation. and I have no idea why. Any help is greatly appreciated.

 

// Get the table and the newly created record

let table = base.getTable('Table Name'); 

 

let recordId = input.config().recordId; // The ID of the newly created record

 

let record = await table.selectRecordAsync('recordId');

 

// List of users to assign randomly

const users = [' User1 ', ' User2 ', ' User3 '];

// Pick a random user

let randomUser = users[Math.floor(Math.random() * users.length)];

 

// Update the Assignee field with the selected user

await table.updateRecordAsync( 'recordId', { 'Assignee': randomUser

});

Forum|alt.badge.img+1

Hello!

Let's break down the issue and get your script working. The error "Error: Request parameters failed validation" in Airtable scripts usually means that the data you're trying to send to the API doesn't match the expected format or has incorrect values.

Here's a breakdown of the problems and the corrected script:

Problems:

Incorrect Record Fetch:
table.selectRecordAsync('recordId') is incorrect. selectRecordAsync expects the actual record ID, not the string 'recordId'.
You should be using the recordId variable you got from input.config().recordId.
Incorrect Record Update:
Similar to the fetch, table.updateRecordAsync('recordId', ...) is incorrect. It should be table.updateRecordAsync(recordId, ...)
Whitespace in User Names:
Your users array has extra whitespace around the user names (e.g., ' User1 '). This can cause issues if your "Assignee" field expects exact matches without leading/trailing spaces.
Corrected Script:

JavaScript

 

let table = base.getTable('Table Name');
let recordId = input.config().recordId; // The ID of the newly created record

if (!recordId) {
    output.text("No record ID provided.");
    return;
}

let record = await table.selectRecordAsync(recordId);

if (!record) {
    output.text(`Record with ID ${recordId} not found.`);
    return;
}

// List of users to assign randomly (remove extra spaces)
const users = ['User1', 'User2', 'User3'];

// Pick a random user
let randomUser = users[Math.floor(Math.random() * users.length)];

// Update the Assignee field with the selected user
try {
    await table.updateRecordAsync(recordId, {
        'Assignee': randomUser,
    });
    output.text(`Record ${recordId} updated with Assignee: ${randomUser}`);
} catch (error) {
    output.text(`Error updating record: ${error.message}`);
}
Explanation of Changes:

Correct Record Fetch:
let record = await table.selectRecordAsync(recordId); now uses the correct recordId variable.
Correct Record Update:
await table.updateRecordAsync(recordId, { 'Assignee': randomUser }); now uses the correct recordId variable.
Whitespace Removal:
The users array is corrected to ['User1', 'User2', 'User3'] to remove the extra spaces.
Error Handling:
Added if statements to check if recordId is present, and if the record exists.
Added a try catch block to catch any errors that might occur during the updateRecordAsync function, and display the error message.
Output Messages:
Added output messages to inform the user of the scripts progress, and any errors that might occur.
How to Use:

Replace 'Table Name': Make sure to replace 'Table Name' with the actual name of your table in Airtable.
Replace 'Assignee': Ensure 'Assignee' matches the exact field name in your table.
Configure Input:
When you run the script in Airtable's scripting app, you need to configure the input. Click the "Input variables" button and add a variable named recordId.
The recordId should be passed into the script from a trigger or another automation.
User Names:
Ensure the user names in the users array match the exact values you have in your "Assignee" field in Airtable.
By making these changes, your script should now correctly fetch the record and update the "Assignee" field without validation errors. I hope this helps!


Reply