Help

Re: Create record via api with key specified

Solved
Jump to Solution
1800 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Steven_Hollande
4 - Data Explorer
4 - Data Explorer

Currently in REST API - Airtable for my base, I see this in description for creating a record:

Your request body should include an array of up to 10 record objects. Each of these objects should have one key whose value is an inner object containing your record's cell values, keyed by either field name or field id.

But when I use this code:

table.create([{
  "key": { "id": "45673157744282"},
  "fields": {
    "purchase_date": "2022-01-08T01:49:22Z",
    "orderID": "155-5041239-4465010",
    "order_status": "Shipped",
    "sales_channel": "Amazon.com",
  // .....
  }
},]).then(result => {
  console.log("Result=", result);
}).catch(err => console.log("Error=", err));

I get this error:

AirtableError {
  error: 'INVALID_REQUEST_UNKNOWN',
  message: 'Invalid request: parameter validation failed. Check your request data.',
  statusCode: 422

So all I need to do is to be able to pass the key (id of the record to be created) while calling the .create().
How do I do it?

1 Solution

Accepted Solutions
Kamille_Parks
16 - Uranus
16 - Uranus

You gave it an object with two keys. Your first key is “key” and your second key is “fields”. Get rid of “key”. If “id” is a field you’re trying to fill in, put it with the rest of your other field values.

You can’t pass the actual record ID of a record that is about to be created because it doesn’t exist yet; it doesn’t have an ID to pass.

See Solution in Thread

1 Reply 1
Kamille_Parks
16 - Uranus
16 - Uranus

You gave it an object with two keys. Your first key is “key” and your second key is “fields”. Get rid of “key”. If “id” is a field you’re trying to fill in, put it with the rest of your other field values.

You can’t pass the actual record ID of a record that is about to be created because it doesn’t exist yet; it doesn’t have an ID to pass.