Introduction to Knack API Integration

Knack is a powerful low-code platform that allows you to build online databases and custom web applications.

When integrating Knack with your own systems or custom front ends, you can use its REST API to access and manipulate your data programmatically.

This guide introduces how to retrieve and list records from a Knack app using PHP. You’ll learn how to authenticate requests, fetch records from a specific object, and display them in a basic list.

Prerequisites

Before you begin, make sure you have:

API Endpoint for Retrieving Records

To retrieve records from an object, you'll use the following endpoint:

GET https://api.knack.com/v1/objects/object_{object_id}/records

You’ll need to pass authentication headers in every request:

Example in PHP

Here’s a simple PHP script that retrieves and lists records from a Knack object:

<?php
$apiKey = 'YOUR_API_KEY';
$appId = 'YOUR_APP_ID';
$objectId = 'YOUR_OBJECT_ID';

$url = "https://api.knack.com/v1/objects/object_$objectId/records";

$headers = [
    "X-Knack-Application-Id: $appId",
    "X-Knack-REST-API-Key: $apiKey",
    "Content-Type: application/json"
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);

if (!empty($data['records'])) {
    echo "<ul>";
    foreach ($data['records'] as $record) {
        echo "<li>" . htmlspecialchars($record['field_1']) . "</li>"; // replace 'field_1' with your actual field key
    }
    echo "</ul>";
} else {
    echo "No records found.";
}
?>

Notes:

Ready to elevate your website?

Whether you're launching a new site, strengthening security, or adding a new feature, I can help transform your vision into a high-performing online presence.

Discuss your web development project