ContioReach Logo
ContioReach
Documentation

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.

  1. 1Navigate to Developer Settings in your ContioReach workspace
  2. 2Under API Keys section, you'll find your blog API key
  3. 3Copy the API key for use in your application

Environment Setup

Add these environment variables to your .env.local file:

.env.local
CMS_API_KEY=your_api_key_here
CMS_API_URL=https://contioreach.com/api/public

Usage Example

Create a helper function to fetch data from the API:

lib/cms.js
// 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
# 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

  1. 1Navigate to Developer Settings in your ContioReach workspace
  2. 2Select the Webhook Integration tab
  3. 3Enter the URL where your Next.js blog is deployed
  4. 4Click Generate to create a secure token
  5. 5Click 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_token

2. Create a revalidation API route in app/api/revalidate/route.js:

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: