For the complete documentation index, see llms.txt. This page is also available as Markdown.

Quickstart

Learn how to use the GitBook API within minutes

The GitBook API allows you to read and write information across the spaces and pages you have access to in GitBook.

You can use the GitBook API to:

…and much more, all via simple REST calls.

1

Getting started

You’ll need a GitBook account to start using the developer platform. If you don’t already have an account, you can sign up for free here.

2

Create a personal access token

After creating a GitBook account, you'll be able to create a personal access token in your developer settings.

This token represents your user in GitBook, and allows you to make API calls, create integrations, and publish them to any GitBook spaces you're a part of to test them.

Once you have your personal access token, you'll want to understand the differences between the pieces of the GitBook Integrations Platform in order to start developing your first app.

3

Make your first API call

The example below shows how to make an API call that asks GitBook Assistant a question in a site within your organization.

To query a GitBook site using the Ask API, send a POST request to the /v1/orgs/{organizationId}/sites/{siteId}/ask endpoint. Include your developer token for authentication, provide the question you want answered, and optionally pass context and scope settings.

Make a basic Ask API request

  1. Set your required headers:

    • Authorization: Bearer YOUR_SECRET_TOKEN

    • Content-Type: application/json

  2. Send a POST request with your query details:

POST /v1/orgs/{organizationId}/sites/{siteId}/ask HTTP/1.1
Host: api.gitbook.com
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
Accept: */*

{
  "question": "How do I get started?",
  "scope": {
    "mode": "default",
  }
}

The API will return an answer generated from your site’s content.

To send a question to the Ask API from JavaScript, you can use GitBook’s client library. After initializing the client with your personal access token, call the askQueryInSpace() method with your organization ID, site ID, and query payload.

Ask a question using GitBook’s JavaScript SDK

  1. Install the GitBook API client:

  1. Initialize the client and send your Ask query:

The response will contain the generated answer based on your site’s content.

To send a question to the Ask API using Python, make a POST request to the /v1/orgs/{organizationId}/sites/{siteId}/ask endpoint. Include your API token for authentication and pass the question, context, and scope in the request body.

Ask a question using Python

This will return the Ask API’s generated answer based on your site’s content.

GitBook’s API has many different API calls that allow you to interact with GitBook in different ways. After sending your first request, head to the API reference to explore the different endpoints GitBook offers.

Explore GitBook’s API

Last updated

Was this helpful?