# REST API Integration

> Part of the [NextBlog documentation](https://nextblog.ai/docs.md). Live page: [https://nextblog.ai/docs/integration-rest-api](https://nextblog.ai/docs/integration-rest-api)

Use our HTTP APIs with an API key. The current, complete API is the [Full REST API](/docs/api-v1.md) at `/api/v1/...` — every dashboard action, the same auth, one error contract, and a public OpenAPI document at [https://nextblog.ai/api/v1/openapi.json](https://nextblog.ai/api/v1/openapi.json) (also served as `/api/v1/openapi.json` from your own deployment). An account key (`nb_u_...`) covers every project; a project key (`nb_...`) covers one.

The original endpoints still work as legacy aliases:

- **Blog Display API** (`/api/blog/...`) — published posts for your website (read-only).
- **Post Management API** (`/api/manage/...`) — create, edit and change post status from your backend.

See [Blog Display API](/docs/endpoints.md) and [Post Management API](/docs/api-manage-posts.md) for those. New integrations should start with v1:

```bash
curl -H "Authorization: Bearer nb_your_project_api_key" \
  "https://nextblog.ai/api/v1/projects/123/posts?limit=10"
```

If you want an AI agent to do the work instead of writing HTTP calls, connect it to the [MCP Server](/docs/mcp.md).

#### Overview

The NextBlog APIs allow you to:

- Fetch all published blog posts for a project (Blog Display API or v1)
- Get a specific published blog post by slug
- Integrate content into custom websites and applications
- Create, update, and change the status of posts
- Generate posts and videos, manage integrations, billing and analytics (v1)

### Step 1: Get Your API Key

#### 1.1 Navigate to Project Settings

1. Log into your NextBlog dashboard
2. Click on your project to open it
3. Click on **"Settings"**

#### 1.2 Generate API Key

1. Scroll to the **"API Key"** section
2. Click **"Generate API Key"** if you don't have one yet
3. Copy your API key and save it securely
4. **Important:** Keep this key secret and never expose it in client-side code

### Step 2: Get Your Project ID

#### 2.1 Find Project ID

Your Project ID can be found:

- In your project settings page
- In the URL when viewing your project: `/projects/PROJECT_ID`
- In the API key section of your project settings

### Step 3: Make API Requests

Published-content reads use `https://nextblog.ai/api/blog`. Advanced create/update flows use `https://nextblog.ai/api/manage` — see [Post Management API](/docs/api-manage-posts.md).

#### 3.1 Base URL (display published posts)

Fetch published posts from:

```bash
https://nextblog.ai/api/blog
```

#### 3.2 Authentication

Include your API key in the Authorization header:

```bash
Authorization: Bearer your_api_key_here
```

#### 3.3 Get All Blog Posts

**Endpoint:** `GET /api/blog/{projectId}`

**Example:**

```bash
curl -H "Authorization: Bearer your_api_key_here" \
    https://nextblog.ai/api/blog/project_123
```

#### 3.4 Get Single Blog Post

**Endpoint:** `GET /api/blog/{projectId}/{slug}`

**Example:**

```bash
curl -H "Authorization: Bearer your_api_key_here" \
    https://nextblog.ai/api/blog/project_123/how-to-optimize-website
```

#### 3.5 Post Management API (optional)

To list drafts, create posts, or update status over HTTP, use the management base URL and endpoints documented on the [Post Management API](/docs/api-manage-posts.md) page.

```bash
https://nextblog.ai/api/manage/{projectId}/posts
```

#### 3.6 Full REST API (recommended)

`/api/v1` supersedes both legacy bases and is the only one that covers generation, integrations, connections, billing and analytics. It is documented end-to-end in [Full REST API](/docs/api-v1.md) and machine-readable at `/api/v1/openapi.json`.

### Response Format

#### All Posts Response

```json
{
  "project": {
    "id": "project_123",
    "name": "My Blog"
  },
  "blogs": [
    {
      "id": "blog_456",
      "title": "How to Optimize Your Website",
      "slug": "how-to-optimize-website",
      "description": "Learn the best practices...",
      "cover_image_url": "https://example.com/image.jpg",
      "published": true,
      "created_at": "2024-01-01T00:00:00Z"
    }
  ]
}
```

#### Single Post Response

```json
{
  "project": {
    "id": "project_123",
    "name": "My Blog"
  },
  "blog": {
    "id": "blog_456",
    "title": "How to Optimize Your Website",
    "slug": "how-to-optimize-website",
    "description": "Learn the best practices...",
    "markdown": "# Full markdown content...",
    "cover_image_url": "https://example.com/image.jpg",
    "published": true,
    "created_at": "2024-01-01T00:00:00Z"
  }
}
```

### Integration Examples

See our detailed examples for:

- [Next.js Integration](/docs/nextjs-examples.md)
- [React Integration](/docs/react-examples.md)
- [JavaScript Integration](/docs/javascript-examples.md)

### Rate Limits

Requests are limited to **120 per minute and 1,000 per hour per credential** (shared across the legacy bases, the Full REST API and MCP). Generation and video calls have their own stricter caps. Exceeding a limit returns `429 Too Many Requests` with `Retry-After`. Full details: [Full REST API → Rate limits](/docs/api-v1.md#rate-limits).

### Security Best Practices

- Never expose your API key in client-side code
- Use environment variables to store API keys
- Rotate your API keys regularly
- Monitor API usage for suspicious activity
