Api
Code Examples
Worked examples for the public API in cURL, JavaScript, Python and PHP.
cURL Examples
Fetch all pages:
curl -H "X-API-Key: tento_pk_your_key_here" \
https://tento-api.intelligentlending.co.uk/api/v1/pages
Fetch blog posts with title only:
curl -H "X-API-Key: tento_pk_your_key_here" \
"https://tento-api.intelligentlending.co.uk/api/v1/pages?pageType=blog-post&fields=title"
Fetch single page:
curl -H "X-API-Key: tento_pk_your_key_here" \
https://tento-api.intelligentlending.co.uk/api/v1/pages/about-us
Conditional request with ETag:
curl -H "X-API-Key: tento_pk_your_key_here" \
-H "If-None-Match: \"a1b2c3d4\"" \
https://tento-api.intelligentlending.co.uk/api/v1/pages/about-us
JavaScript (Fetch API) Examples
Basic fetch:
const response = await fetch('https://tento-api.intelligentlending.co.uk/api/v1/pages', {
headers: {
'X-API-Key': 'tento_pk_your_key_here'
}
})
const data = await response.json()
console.log(data.data) // Array of pages
console.log(data.pagination) // Pagination info
Fetch with error handling:
async function fetchPages() {
try {
const response = await fetch('https://tento-api.intelligentlending.co.uk/api/v1/pages', {
headers: { 'X-API-Key': process.env.CMS_API_KEY }
})
if (!response.ok) {
const error = await response.json()
throw new Error(error.error.message)
}
return await response.json()
} catch (error) {
console.error('Failed to fetch pages:', error)
return { data: [], pagination: { total: 0 } }
}
}
Fetch single page with redirect handling:
async function fetchPage(slug) {
const response = await fetch(
`https://tento-api.intelligentlending.co.uk/api/v1/pages/${slug}`,
{ headers: { 'X-API-Key': process.env.CMS_API_KEY } }
)
if (response.status === 404) {
return null
}
const { data, redirect } = await response.json()
if (redirect) {
console.log(`Redirect: ${redirect.from} -> ${redirect.to}`)
// Update browser URL if needed
window.history.replaceState(null, '', `/${redirect.to}`)
}
return data
}
Pagination helper:
async function fetchAllPages(filters = {}) {
const pages = []
let page = 1
const limit = 100
while (true) {
const params = new URLSearchParams({
page: page.toString(),
limit: limit.toString(),
...filters
})
const response = await fetch(
`https://tento-api.intelligentlending.co.uk/api/v1/pages?${params}`,
{ headers: { 'X-API-Key': process.env.CMS_API_KEY } }
)
const { data, pagination } = await response.json()
pages.push(...data)
if (pagination.page >= pagination.totalPages) break
page += 1
}
return pages
}
// Usage
const allBlogPosts = await fetchAllPages({ pageType: 'blog-post' })
Python (requests) Examples
Basic fetch:
import requests
import os
API_KEY = os.environ['CMS_API_KEY']
BASE_URL = 'https://tento-api.intelligentlending.co.uk/api/v1'
response = requests.get(
f'{BASE_URL}/pages',
headers={'X-API-Key': API_KEY}
)
data = response.json()
pages = data['data']
pagination = data['pagination']
Fetch with error handling:
def fetch_pages(page_type=None, fields=None):
params = {}
if page_type:
params['pageType'] = page_type
if fields:
params['fields'] = ','.join(fields)
try:
response = requests.get(
f'{BASE_URL}/pages',
headers={'X-API-Key': API_KEY},
params=params
)
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 401:
print('API key invalid or expired')
elif e.response.status_code == 429:
print('Rate limited')
raise
Fetch single page:
def fetch_page(slug):
response = requests.get(
f'{BASE_URL}/pages/{slug}',
headers={'X-API-Key': API_KEY}
)
if response.status_code == 404:
return None
response.raise_for_status()
data = response.json()
if data['redirect']:
print(f"Redirect: {data['redirect']['from']} -> {data['redirect']['to']}")
return data['data']
Pagination helper:
def fetch_all_pages(page_type=None):
pages = []
page = 1
limit = 100
while True:
params = {'page': page, 'limit': limit}
if page_type:
params['pageType'] = page_type
response = requests.get(
f'{BASE_URL}/pages',
headers={'X-API-Key': API_KEY},
params=params
)
response.raise_for_status()
data = response.json()
pages.extend(data['data'])
if data['pagination']['page'] >= data['pagination']['totalPages']:
break
page += 1
return pages
# Usage
all_blog_posts = fetch_all_pages('blog-post')
Rate limiting with retry:
import time
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
def create_session():
session = requests.Session()
retry_strategy = Retry(
total=3,
status_forcelist=[429, 500, 502, 503, 504],
allowed_methods=["GET"],
backoff_factor=2
)
adapter = HTTPAdapter(max_retries=retry_strategy)
session.mount("https://", adapter)
session.mount("http://", adapter)
return session
session = create_session()
response = session.get(
f'{BASE_URL}/pages',
headers={'X-API-Key': API_KEY}
)
PHP Examples
Basic fetch:
<?php
$apiKey = getenv('CMS_API_KEY');
$baseUrl = 'https://tento-api.intelligentlending.co.uk/api/v1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$baseUrl/pages");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: $apiKey"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$data = json_decode($response, true);
$pages = $data['data'];
$pagination = $data['pagination'];
} else {
$error = json_decode($response, true);
echo "Error: " . $error['error']['message'];
}
Fetch with query parameters:
<?php
function fetchPages($type = null, $fields = null, $limit = 20, $page = 1) {
global $apiKey, $baseUrl;
$params = [
'page' => $page,
'limit' => $limit
];
if ($type) $params['pageType'] = $type;
if ($fields) $params['fields'] = implode(',', $fields);
$url = "$baseUrl/pages?" . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: $apiKey"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception("API error: $httpCode");
}
return json_decode($response, true);
}
// Usage
$blogPosts = fetchPages('blog-post', ['title', 'excerpt'], 10, 0);
Fetch single page:
<?php
function fetchPage($slug) {
global $apiKey, $baseUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$baseUrl/pages/$slug");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: $apiKey"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 404) {
return null;
}
if ($httpCode !== 200) {
throw new Exception("API error: $httpCode");
}
$data = json_decode($response, true);
if ($data['redirect']) {
// Handle redirect
header("Location: /" . $data['redirect']['to'], true, 301);
exit;
}
return $data['data'];
}
// Usage
$page = fetchPage('about-us');
Pagination helper:
<?php
function fetchAllPages($type = null) {
$allPages = [];
$page = 1;
$limit = 100;
do {
$response = fetchPages($type, null, $limit, $page);
$allPages = array_merge($allPages, $response['data']);
$hasMore = $response['pagination']['page'] < $response['pagination']['totalPages'];
$page += 1;
} while ($hasMore);
return $allPages;
}
// Usage
$allBlogPosts = fetchAllPages('blog-post');

