Create record via api with key specified

Topic Labels: API
755 1
Showing results for 
Search instead for 
Did you mean: 
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:

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

I get this error:

AirtableError {
  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 Reply 1

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.