Back to Integrations

API Integration

Display the articles RankBolt writes on your own website, with your own design.

Setup time

~10 minutes

Auth method

API key (Bearer)

Content format

Markdown

Watch the full setup

Get your API key, add it to a Next.js site, show your articles and publish a new one, in under 3 minutes.

Prerequisites

  • A RankBolt API key (Settings → Integrations)
  • At least one published article
  • A website that can fetch data on the server, so your key stays private

Step-by-step setup

More frameworks coming soon.
1

Add your API key

Copy your key from Settings → Integrations and add it to .env.local at the root of your project.

.env.local
RANKBOLT_API_KEY=your_api_key
Keep the key on the server. Never prefix it with NEXT_PUBLIC_, or it ships to every visitor's browser.
2

Install a Markdown renderer

The API returns each article body as Markdown. react-markdown turns it into HTML.

Terminal
npm install react-markdown remark-gfm
3

Create the API helper

One file that calls the RankBolt API with your key and caches the answer for 60 seconds.

lib/rankbolt.ts
const API = "https://rankbolt.ai/api/v1";

export type Article = {
  id: string;
  slug: string | null;
  title: string;
  excerpt: string | null;
  content: string; // Markdown
  featured_image: string | null;
  published_at: string | null;
  meta_title: string | null;
  meta_description: string | null;
  reading_time: number | null;
  author: { name: string; image: string | null } | null;
  tags: { id: number; name: string; slug: string }[];
};

async function rankbolt<T>(path: string): Promise<T | null> {
  const res = await fetch(`${API}${path}`, {
    headers: { Authorization: `Bearer ${process.env.RANKBOLT_API_KEY}` },
    next: { revalidate: 60 }, // refresh at most once a minute
  });
  if (res.status === 404) return null;
  if (!res.ok) throw new Error(`RankBolt API error ${res.status}`);
  return res.json();
}

export async function getArticles(limit = 9, offset = 0) {
  const json = await rankbolt<{
    data: Article[];
    meta: { total: number; limit: number; offset: number };
  }>(`/articles?limit=${limit}&offset=${offset}`);
  return json ?? { data: [], meta: { total: 0, limit, offset } };
}

export async function getArticle(slug: string) {
  const json = await rankbolt<{ data: Article }>(
    `/articles/${encodeURIComponent(slug)}`,
  );
  return json?.data ?? null;
}
4

Create the blog list page

A server component that lists your published articles, newest first.

app/blog/page.tsx
import Link from "next/link";
import { getArticles } from "@/lib/rankbolt";

export default async function BlogPage() {
  const { data: articles } = await getArticles(9);

  return (
    <main className="mx-auto max-w-5xl px-6 py-16">
      <h1 className="text-4xl font-semibold">Blog</h1>
      <div className="mt-10 grid gap-8 md:grid-cols-3">
        {articles.map((article) => (
          <Link key={article.id} href={`/blog/${article.slug}`}>
            {article.featured_image && (
              <img
                src={article.featured_image}
                alt={article.title}
                className="rounded-xl"
              />
            )}
            <h2 className="mt-4 text-xl font-medium">{article.title}</h2>
            <p className="mt-2 text-sm text-gray-600">{article.excerpt}</p>
          </Link>
        ))}
      </div>
    </main>
  );
}
5

Create the article page

Renders one article and sets its SEO title, description and share image.

app/blog/[slug]/page.tsx
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import Markdown from "react-markdown";
import remarkGfm from "remark-gfm";
import { getArticle } from "@/lib/rankbolt";

type Props = { params: Promise<{ slug: string }> };

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { slug } = await params;
  const article = await getArticle(slug);
  if (!article) return {};

  return {
    title: article.meta_title ?? article.title,
    description: article.meta_description ?? article.excerpt ?? undefined,
    openGraph: {
      images: article.featured_image ? [article.featured_image] : [],
    },
  };
}

export default async function ArticlePage({ params }: Props) {
  const { slug } = await params;
  const article = await getArticle(slug);
  if (!article) notFound();

  return (
    <article className="prose mx-auto max-w-3xl px-6 py-16">
      <h1>{article.title}</h1>
      {article.published_at && (
        <p className="text-sm text-gray-500">
          {new Date(article.published_at).toLocaleDateString()}
          {article.reading_time ? ` · ${article.reading_time} min read` : ""}
        </p>
      )}
      {article.featured_image && (
        <img src={article.featured_image} alt={article.title} />
      )}
      <Markdown remarkPlugins={[remarkGfm]}>{article.content}</Markdown>
    </article>
  );
}
On Next.js 14, params is a plain object: read params.slug without await. The prose class needs the @tailwindcss/typography plugin.
6

Check the result

Start your dev server and open /blog. Your published articles appear, and each one opens at /blog/your-article-slug.

What the API returns

The same endpoints work from any framework. Send your key in the Authorization header on every request.

GET/api/v1/articles?limit=9&offset=0Published articles, newest first
GET/api/v1/articles/{slug}One article by its slug
GET/api/v1/articles/search?q=seoSearch titles and excerpts
GET/api/v1/tagsAll tags of your site
GET/api/v1/tags/{slug}One tag by its slug
  • Only published articles are returned. Drafts and scheduled articles stay private.
  • Lists return 9 articles by default and 100 at most. Use limit and offset to paginate; meta.total holds the full count.
  • The limit is 100 requests per minute, so keep the cache on.

Troubleshooting

Need your API key?

Generate it in your integration settings, then follow the steps above.

Go to Integrations