This is the Official PHP client for Kontenbase API.
Kontenbase is a no-code backend API platform or Backend as a Service (BaaS) that allows you to create a backend API as fast as possible. We make it easy for developers to build backend API without having to touch backend code at all.
Visit Kontenbase for more information and see our documentation for more technical details.
For API documentation, visit Kontenbase API Reference.
To install the SDK you can use Composer or directly download the source and extract to your directory. If you’re using Composer, run this following command:
composer require kontenbase/sdk
Before you begin, you need to sign up on Kontenbase Dashboard to retrieve an API key of your project.
<?php
use Kontenbase\KontenbaseClient;
$kontenbase = new KontenbaseClient([
'apiKey': 'YOUR_API_KEY' // Your API Key from app.kontenbase.com
]);
$res = $kontenbase->auth->register([
'firstName' => 'Ega',
'lastName' => 'Radiegtya',
'email' => '[email protected]',
'password' => 'password'
]);
echo $res['user']; // The data of registered user
echo $res['token']; // The token of registered user
$res = $kontenbase->auth->login([
'email' => '[email protected]',
'password' => 'password'
]);
echo $res['user']; // The data of logged-in user
echo $res['token']; // The token of logged-in user
$res = $kontenbase->auth->user();
echo $res['user'];
$res = $kontenbase->auth->update([
'firstName' => 'Ega'
]);
echo $res['user'];
$res = $kontenbase->auth->logout();
$res = $kontenbase->service('posts')->create([
'name' => 'Post 1',
'notes' => 'Hello Kontenbase'
]);
echo $res['data'] // The data of the new record
$res = $kontenbase->service('posts')->getById('605a251d7b8678bf6811k3b1');
echo $res['data'] // The data of the record
Get all records
$res = $kontenbase->service('posts')->find();
echo $res['data'] // The data of all records
Find records and modify the result
// limit
$res = $kontenbase->service('posts')->find([
'limit' => 10
]);
// sort
// ascending: 1
// descending: -1
$res = $kontenbase->service('posts')->find([
'sort' => ['name' => 1]
]);
// skip
$res = $kontenbase->service('posts')->find([
'skip' => 10
]);
// select
$res = $kontenbase->service('posts')->find([
'select' => ['name', 'notes']
]);
// lookup all fields
$res = $kontenbase->service('posts')->find([
'lookup' => '*'
]);
// lookup spesific fields
$res = $kontenbase->service('posts')->find([
'lookup' => ['categories']
]);
// lookup but only show ids
$res = $kontenbase->service('posts')->find([
'lookup' => ['_id' => '*']
]);
Find records with criteria
// equals
$res = $kontenbase->service('posts')->find([
'where' => [
'name' => 'Ega'
]
]);
// does not equal
$res = $kontenbase->service('posts')->find([
'where' => [
'name' => ['$ne' => 'Ega']
]
]);
// contains
$res = $kontenbase->service('posts')->find([
'where' => [
'notes' => ['$contains' => 'hello']
]
]);
// does not contain
$res = $kontenbase->service('posts')->find([
'where' => [
'notes' => ['$notContains' => 'hello']
]
]);
// matches any of
$res = $kontenbase->service('posts')->find([
'where' => [
'name' => ['$in' => ['Ega', 'Radiegtya']]
]
]);
// does not match any of
$res = $kontenbase->service('posts')->find([
'where' => [
'name' => ['$nin' => ['Ega', 'Radiegtya']]
]
]);
// less than
$res = $kontenbase->service('posts')->find([
'where' => [
'total' => ['$lt' => 10]
]
]);
// less than or equals
$res = $kontenbase->service('posts')->find([
'where' => [
'total' => ['$lte' => 10]
]
]);
// more than
$res = $kontenbase->service('posts')->find([
'where' => [
'total' => ['$gt' => 10]
]
]);
// more than or equals
$res = $kontenbase->service('posts')->find([
'where' => [
'total' => ['$gte' => 10]
]
]);
$res = $kontenbase->service('posts')->updateById('605a251d7b8678bf6811k3b1', [
'notes' => 'Hello world'
]);
$res = $kontenbase->service('posts')->deleteById('605a251d7b8678bf6811k3b1');
$res = $kontenbase->service('posts')->link('605a251d7b8678bf6811k3b1', [
'categories' => '61d26e8e2adb12b85c33029c'
]);
$res = $kontenbase->service('posts')->unlink('605a251d7b8678bf6811k3b1', [
'categories' => '61d26e8e2adb12b85c33029c'
]);
Count all records
$res = $kontenbase->service('posts')->count();
Count records that match given criteria
$res = $kontenbase->service('posts')->find([
'where' => [
'name' => 'Ega'
]
]);
$file = fopen('/path/to/file', 'r');
$res = $kontenbase->storage->upload($file);
echo $res['data'] // The data of the uploaded file
Please use our GitHub Issues for high-level feedback. Also you can join our Discord server.