Welcome to GitBook
GitBook is a modern documentation platform where teams can document everything from products to internal knowledge bases and APIs. It’s simple to create, manage, and share beautiful books and documentation with GitBook. In this guide, we’ll cover dozens of useful GitBook API integrations with practical code snippets to help you get started.
API Examples
Create a New Book
Use the following API to create a new book in GitBook. Customize the parameters according to your project’s needs.
curl -X POST https://api.gitbook.com/v1/books \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "My New Book",
"visibility": "public"
}'
List All Books
Retrieve a list of all books in your GitBook account.
curl -X GET https://api.gitbook.com/v1/books \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Get Book Details
Retrieve detailed information about a specific book using its identifier.
curl -X GET https://api.gitbook.com/v1/books/BOOK_ID \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Update Book
Update the details of an existing book. Only the fields provided in the request will be updated.
curl -X PATCH https://api.gitbook.com/v1/books/BOOK_ID \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Book Title"
}'
Delete a Book
Delete a book from your GitBook account using its identifier.
curl -X DELETE https://api.gitbook.com/v1/books/BOOK_ID \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
List All Pages in a Book
Retrieve a list of all pages within a specific book.
curl -X GET https://api.gitbook.com/v1/books/BOOK_ID/pages \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Create a New Page
Add a new page to a specific book.
curl -X POST https://api.gitbook.com/v1/books/BOOK_ID/pages \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "New Page Title",
"content": "# New Page Content"
}'
Update a Page
Update the content of an existing page within a book.
curl -X PATCH https://api.gitbook.com/v1/books/BOOK_ID/pages/PAGE_ID \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"content": "# Updated Page Content"
}'
Delete a Page
Remove a page from a specific book using its page identifier.
curl -X DELETE https://api.gitbook.com/v1/books/BOOK_ID/pages/PAGE_ID \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Example Application
Below is an example of a simple Node.js application that demonstrates how to use some of the GitBook APIs mentioned above.
const axios = require('axios');
const API_URL = 'https://api.gitbook.com/v1'; const ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN';
async function createBook(title) {
const response = await axios.post(\`\${API_URL}/books\`, {
title: title,
visibility: 'public'
}, {
headers: {
'Authorization': \`Bearer \${ACCESS_TOKEN}\`,
'Content-Type': 'application/json'
}
});
return response.data;
}
async function listBooks() {
const response = await axios.get(\`\${API_URL}/books\`, {
headers: {
'Authorization': \`Bearer \${ACCESS_TOKEN}\`
}
});
return response.data;
}
async function getBookDetails(bookId) {
const response = await axios.get(\`\${API_URL}/books/\${bookId}\`, {
headers: {
'Authorization': \`Bearer \${ACCESS_TOKEN}\`
}
});
return response.data;
}
async function updateBook(bookId, title) {
const response = await axios.patch(\`\${API_URL}/books/\${bookId}\`, {
title: title
}, {
headers: {
'Authorization': \`Bearer \${ACCESS_TOKEN}\`,
'Content-Type': 'application/json'
}
});
return response.data;
}
async function deleteBook(bookId) {
const response = await axios.delete(\`\${API_URL}/books/\${bookId}\`, {
headers: {
'Authorization': \`Bearer \${ACCESS_TOKEN}\`
}
});
return response.data;
}
(async () => {
const newBook = await createBook('My Awesome Book');
console.log('Book Created:', newBook);
const books = await listBooks();
console.log('Books:', books);
const bookDetails = await getBookDetails(newBook.id);
console.log('Book Details:', bookDetails);
const updatedBook = await updateBook(newBook.id, 'My Even More Awesome Book');
console.log('Book Updated:', updatedBook);
await deleteBook(newBook.id);
console.log('Book Deleted');
})();
By leveraging these APIs, you can automate and manage your documentation process more efficiently. GitBook provides a robust platform for creating, collaborating, and sharing documentation seamlessly.
Hash: f90fc630929a853db0ba5214cde5df933fa66b55fcb08f356533fdb56f5d5c1d