PHP examples: create and filter records
Two PHP cURL snippets for the Tadabase REST API: create a record in a table, and get the records that match a set of filters.
- Verified Nov 17, 2026
- Classic builder
These two snippets call the Tadabase REST API from PHP with cURL. The first creates a record in a table; the second reads the records that match your filters. Copy them into your own code and change the table ID and field slugs.
Before you start #
- An API key for the app with Allow Reads turned on (to get records) and Allow Updates turned on (to create records). Note its App ID, API key and API secret. See Get your API keys.
- The ID of the table, and the slug of each field you write or filter on, such as
field_36. List all tables and field slugs in Google Sheets shows a quick way to collect them. - Put the three key values in environment variables (
TADABASE_APP_ID,TADABASE_API_KEY,TADABASE_API_SECRET) on the server that runs the code. Never paste a real key into code you share or commit.
Create a record #
Send a POST to /api/v1/data-tables/{tableId}/records with one value per field slug. Fields you leave out keep their default value. A connection field takes the IDs of the records to connect.
<?php
// Read the keys from environment variables so they never end up in your code.
$appId = getenv('TADABASE_APP_ID');
$apiKey = getenv('TADABASE_API_KEY');
$apiSecret = getenv('TADABASE_API_SECRET');
$tableId = 'YOUR_TABLE_ID';
// One entry per field slug. Replace the slugs with your table's.
$fields = [
'field_36' => 'Replace the water heater', // Text
'field_40' => 'customer@example.com', // Email
'field_43' => 250, // Number
'field_62' => ['DVWQWRNZ49'], // Connection: IDs of the records to connect
];
$ch = curl_init('https://api.tadabase.io/api/v1/data-tables/' . $tableId . '/records');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($fields),
CURLOPT_HTTPHEADER => [
'X-Tadabase-App-Id: ' . $appId,
'X-Tadabase-App-Key: ' . $apiKey,
'X-Tadabase-App-Secret: ' . $apiSecret,
],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($body, true);
if ($status !== 200 || ($result['type'] ?? '') !== 'success') {
$message = is_string($result['msg'] ?? null) ? $result['msg'] : $body;
throw new RuntimeException('Tadabase API error ' . $status . ': ' . $message);
}
echo 'Created record ' . $result['recordId'] . PHP_EOL; On success the API answers with type set to success, the new record's ID in recordId, and the message The record has been successfully saved.
Get records with filters #
Send a GET to the same address with the filters in the query string. Each item names a field slug, an operator and a value. This example returns the records whose email is customer@example.com and whose status is Open, 100 records per page.
<?php
$appId = getenv('TADABASE_APP_ID');
$apiKey = getenv('TADABASE_API_KEY');
$apiSecret = getenv('TADABASE_API_SECRET');
$tableId = 'YOUR_TABLE_ID';
$query = http_build_query([
'filters' => [
'items' => [
['field_id' => 'field_40', 'operator' => 'is', 'val' => 'customer@example.com'],
['field_id' => 'field_50', 'operator' => 'is', 'val' => 'Open'],
],
],
'limit' => 100,
'page' => 1,
]);
$ch = curl_init('https://api.tadabase.io/api/v1/data-tables/' . $tableId . '/records?' . $query);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-Tadabase-App-Id: ' . $appId,
'X-Tadabase-App-Key: ' . $apiKey,
'X-Tadabase-App-Secret: ' . $apiSecret,
],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($body, true);
if ($status !== 200 || ($result['type'] ?? '') !== 'success') {
$message = is_string($result['msg'] ?? null) ? $result['msg'] : $body;
throw new RuntimeException('Tadabase API error ' . $status . ': ' . $message);
}
foreach ($result['items'] as $record) {
echo $record['id'] . ': ' . $record['field_40'] . PHP_EOL;
}
echo $result['total_items'] . ' records on ' . $result['total_pages'] . ' pages' . PHP_EOL; - The filter items are combined with AND. To return records that match any item, add
'condition' => 'OR'next to'items'. - A filter on a field slug the table does not have is refused with an error instead of being ignored.
- The response holds the records in
items, plustotal_items,total_pages,current_pageandlimit. Records come back in ID order unless you sort them. To read every match, repeat the call withpageset to 2, 3 and so on up tototal_pages. - A
limitabove the server's maximum is lowered to that maximum, so ask for 100 at a time. - For every operator and more filter shapes, see Filtering records.
Common problems #
| What you see | What to do |
|---|---|
The method being used is disabled for this API key. (status 412) | Turn on Allow Reads (for GET) or Allow Updates (for POST) on the API key. |
Data Table not found | Check the table ID. It must be a table of the app the key belongs to. |
No Fields Supplied to be Saved. | The POST body was empty. Check that CURLOPT_POSTFIELDS holds your fields. |
| Status 429 | You sent too many requests. Wait the number of seconds in the Retry-After header, then try again. See Rate limiting. |
Was this page helpful?
Something wrong or missing on this page? Tell us.