Getting Started
Welcome to Contioreach API! This guide will help you get started with integrating our API into your application.
Getting Your API Key
To use the Contioreach API, you'll need to generate an API key from your workspace's Developer Settings.
- Navigate to Developer Settings in your Contioreach workspace
- Under API Keys section, you'll find your blog API key
- Copy the API key for use in your application
Environment Setup
Add these environment variables to your .env.local file:
CMS_API_KEY=your_api_key_here CMS_API_URL=https://contioreach.com/api/publicUsage Example
Create a helper function to fetch data from the API:
// lib/cms.js
export async function getAllPosts() {
const res = await fetch(
process.env.CMS_API_URL + '/post',
{
headers: {
'X-API-Key': process.env.CMS_API_KEY
}
}
);
if (!res.ok) {
throw new Error('Failed to fetch posts');
}
const data = await res.json();
return data.data;
}Authentication
All API endpoints require authentication using your API key.
The API key should be included in your requests using the X-API-Key header.
# Test with cURL
curl -X GET "https://contioreach.com/api/public/post" -H "X-API-Key: your_api_key_here"Webhook Integration
Webhooks enable automatic content revalidation in your Next.js application when content is published in Contioreach.
Why Use Webhooks?
With webhooks, your blog automatically updates when you publish or update content in Contioreach, eliminating the need for manual rebuilds or waiting for a scheduled revalidation.
Configuration Steps
- Navigate to Developer Settings in your Contioreach workspace
- Select the Webhook Integration tab
- Enter the URL where your Next.js blog is deployed
- Click Generate to create a secure token
- Click Save Configuration to activate the webhook
Setup Revalidation in Next.js
1. Add the secret token to your .env.local file:
REVALIDATION_SECRET=your_generated_secret_token2. Create a revalidation API route in app/api/revalidate/route.js:
import { revalidatePath } from 'next/cache';
import { NextResponse } from 'next/server';
export async function POST(request) {
const { secret, post } = await request.json();
if (secret !== process.env.REVALIDATION_SECRET) {
return NextResponse.json({ error: 'Invalid token' }, { status: 401 });
}
// Always revalidate the blog index
revalidatePath('/blog');
// Revalidate the specific post page if a post slug is provided
if (post?.slug) {
const postPath = '/blog/' + post.slug;
revalidatePath(postPath);
}
return NextResponse.json({ revalidated: true, paths });
}When content is published in Contioreach, the webhook will automatically trigger this endpoint, revalidating the specified paths in your Next.js application and ensuring your content stays up-to-date.
Next Steps
Check out the API reference to learn more about the available endpoints: