How to I insert records into link fields with API?
I’m trying to insert a new record into a table that has a link field (single select). The value I’m trying to insert matches exactly with the value in the linked table but I’m getting a 422 error.
To do this do I need to insert the record ID in the linked table? I don’t have this ID available in my external application.
Page 1 / 1
If you are trying to modify a linked record field (or create a new record with a linked record field), you do need to use the foreign record’s ID. If you don’t have those IDs readily available, you can look them up via a GET request and use the filterByFormula query parameter to find the foreign record ID. For example, if you’re foreign record’s primary key is called “Name” with a value “Record1”, you could find the record by doing:
curl -X GET 'https://api.airtable.com/v0/YOUR_BASE_ID/YOUR_FOREIGN_TABLE_NAME?filterByFormula={Name}=%22Record1%22'
This will return a list of records that match that formula. If your primary keys are unique, there will only be one record in the list and you can retrieve it’s record ID.
You could also try and use the typecast parameter when creating the new record. Using typecast will ask the Airtable API to try and infer the intention of the request. You can use the foreign record’s primary key instead of it’s record ID, and the API will attempt to find the corresponding linked record and make the connection:
If you are trying to modify a linked record field (or create a new record with a linked record field), you do need to use the foreign record’s ID. If you don’t have those IDs readily available, you can look them up via a GET request and use the filterByFormula query parameter to find the foreign record ID. For example, if you’re foreign record’s primary key is called “Name” with a value “Record1”, you could find the record by doing:
curl -X GET 'https://api.airtable.com/v0/YOUR_BASE_ID/YOUR_FOREIGN_TABLE_NAME?filterByFormula={Name}=%22Record1%22'
This will return a list of records that match that formula. If your primary keys are unique, there will only be one record in the list and you can retrieve it’s record ID.
You could also try and use the typecast parameter when creating the new record. Using typecast will ask the Airtable API to try and infer the intention of the request. You can use the foreign record’s primary key instead of it’s record ID, and the API will attempt to find the corresponding linked record and make the connection:
You’re right! Passing the record ID inside an array worked!
I was trying to pass the string value and was getting an error. Thanks for the quick help!
Encountered this as well and for those that it might help, the typecast parameter only works for string values. So the primary field you are linking to must be a text field. I tried this with a number field as the primary field and it kept creating new records even though one already existed.
How can I use this in Laravel? Can I use something like this?
$ids = =
“Company_tags” => =$id]
];
$response = Http::withHeaders(a
'Content-Type' => 'application/json',
'Authorization' => env('AIRTABLE_API_KEY')
])->post('https://api.airtable.com/v0/'.env('AIRTABLE_BASE_ID').'/'.env('AIRTABLE_CAND_TABLE'), L
"typecast" => true,
"fields" => =
"Company_tags" => =$id],
],
]);
If you are trying to modify a linked record field (or create a new record with a linked record field), you do need to use the foreign record’s ID. If you don’t have those IDs readily available, you can look them up via a GET request and use the filterByFormula query parameter to find the foreign record ID. For example, if you’re foreign record’s primary key is called “Name” with a value “Record1”, you could find the record by doing:
curl -X GET 'https://api.airtable.com/v0/YOUR_BASE_ID/YOUR_FOREIGN_TABLE_NAME?filterByFormula={Name}=%22Record1%22'
This will return a list of records that match that formula. If your primary keys are unique, there will only be one record in the list and you can retrieve it’s record ID.
You could also try and use the typecast parameter when creating the new record. Using typecast will ask the Airtable API to try and infer the intention of the request. You can use the foreign record’s primary key instead of it’s record ID, and the API will attempt to find the corresponding linked record and make the connection: