microCMS JavaScript SDK

3.4.0 · active · verified Sun Apr 19

The `microcms-js-sdk` is the official JavaScript SDK client designed to interact with microCMS Content APIs and Management APIs from both Node.js and browser environments. Currently at stable version `3.4.0`, it receives regular updates, with several minor and patch releases in recent months, alongside a significant major update to v3.0.0. Key differentiators include its comprehensive support for microCMS's List and Object API formats, methods for common operations like content retrieval (`getList`, `getListDetail`, `getObject`), content creation, updating, and deletion. It also offers features like `getAllContents` and `getAllContentIds` for advanced retrieval patterns and a Management API client for tasks such as image uploads (introduced in v3.1.0). The SDK is type-safe as it ships with TypeScript definitions, making it suitable for modern JavaScript and TypeScript projects. Users should be aware of the breaking changes introduced in v3.0.0, particularly the shift to `global fetch` and a Node.js v18+ runtime requirement.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the microCMS client and fetches a paginated list of blog content, demonstrating querying with filters and field selection. It includes basic TypeScript typing for the content structure.

import { createClient } from 'microcms-js-sdk';

interface MyContent {
  id: string;
  title: string;
  description: string;
  createdAt: string;
  updatedAt: string;
  publishedAt: string;
  revisedAt: string;
}

const client = createClient({
  serviceDomain: process.env.MICROCMS_SERVICE_DOMAIN ?? 'YOUR_SERVICE_DOMAIN',
  apiKey: process.env.MICROCMS_API_KEY ?? 'YOUR_API_KEY',
});

async function fetchContentList() {
  try {
    const response = await client.getList<MyContent>({
      endpoint: 'blogs',
      queries: {
        limit: 5,
        offset: 0,
        orders: '-publishedAt',
        fields: 'id,title,publishedAt',
        filters: 'publishedAt[less_than]2026-12-31T23:59:59.999Z'
      }
    });
    console.log('Fetched content list:', JSON.stringify(response, null, 2));
    return response;
  } catch (error) {
    console.error('Error fetching content:', error);
    throw error;
  }
}

fetchContentList();

view raw JSON →