Quick Start

Get up and running with the Contensa.ai SDK in under 5 minutes. This guide walks you through installing the SDK, finding your credentials, and fetching your first content.

Before You Begin

You will need three things from your Contensa.ai dashboard before writing any code:

1. API Key

Authenticates your application. From your project dashboard, click the Manage Keys button (or Generate Key if none exists yet) to open the API key modal. Click the eye icon to reveal and copy the full key.

How to get an API key →

2. Content Type ID

The unique identifier for a content model (e.g. "Blog Post"). In the dashboard, go to Content Model, open the model you want, and click the Copy ID button in the top-right corner of the page.

What is a content model? →

3. Project ID

Your project's unique identifier. Go to your project Settings page — it is displayed as Project ID and can be copied with the button next to it. It matches the URL slug you see in the dashboard address bar.

1. Install the SDK

npm install @mybe/sdk

2. Initialize the SDK

Create an instance of the SDK using your API key. Always load secrets from environment variables — never hardcode them.

import { MybeSDK } from '@mybe/sdk';

const sdk = new MybeSDK({
  apiKey: process.env.CONTENSA_API_KEY, // from Settings → API Keys
});

Where is my API key?

From your project dashboard home page, find the API Keys card and click Manage Keys (or Generate Key if you don't have one yet). The modal shows your key — use the eye icon to reveal the full key and copy it. Store it securely, as the full key is only temporarily retrievable and will become unavailable after a short window.
# .env.local
CONTENSA_API_KEY=your-api-key-here

3. Fetch Content by Type

The most common operation is fetching all entries of a content type — for example, all blog posts. You need the Content Type ID of the model you want to query.

// Replace with your actual Content Type ID
const result = await sdk.getContentByType('your-content-type-id', {
  status: 'published',
  limit: 10,
});

console.log(result.data);        // Array of content entries
console.log(result.pagination);  // { hasMore, lastEvaluatedKey }

Where is my Content Type ID?

Dashboard → Content Model (left sidebar) → click the name of the model you want (e.g. "Blog Post") → look for the Copy ID button in the top-right corner of the detail page. The copied value is the Content Type ID you pass to getContentByType().

4. Fetch a Single Content Entry

If you know the ID of a specific content entry (not the content type, but a single piece of content), use getContent().

// Fetch one specific content entry by its entry ID
const content = await sdk.getContent('entry-id-here');

console.log(content.data);    // The entry's field values
console.log(content.status);  // 'draft' | 'published' | 'archived'

Content Type ID vs Content Entry ID

A Content Type ID identifies the schema (e.g. the "Blog Post" model). A Content Entry ID identifies one specific piece of content created from that schema (e.g. the "Hello World" post). These are different — getContentByType() takes a Type ID; getContent() takes an Entry ID.

5. Fetch Content by Slug or Custom Field

Useful for dynamic routes — fetch a page by its URL slug or any unique field value.

// Fetch a blog post where the 'slug' field equals 'hello-world'
const post = await sdk.getContentByField(
  'your-content-type-id', // Content Type ID from dashboard
  'slug',                  // Field name defined in your content model
  'hello-world'            // Value to match
);

if (post) {
  console.log(post.data.title);
} else {
  // No content found — returns null instead of throwing
}

6. Handle Errors

import { NotFoundError, UnauthorizedError } from '@mybe/sdk';

try {
  const content = await sdk.getContent('entry-id-here');
} catch (error) {
  if (error instanceof NotFoundError) {
    // The entry ID doesn't exist
    console.error('Content not found');
  } else if (error instanceof UnauthorizedError) {
    // API key is missing, invalid, or expired
    console.error('Check your API key in Settings → API Keys');
  }
}

Next Steps

  • Authentication — learn about key types (read-only vs read-write) and security best practices
  • Content Models — understand what content models and references are, and how to create them
  • API Reference — full list of SDK methods with parameters and return types
  • GraphQL — query your content using GraphQL for more flexible data fetching