> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/developers/integrations/development/client-library.md).

# Client library

GitBook provides an official TypeScript and JavaScript client for the [HTTP API](/docs/developers/gitbook-api/api-reference.md). Use it in browsers or Node.js.

### Install

The GitBook CLI installs the client when you [bootstrap an integration](/docs/developers/integrations/quickstart.md#bootstrap-your-app). To add it manually, run:

```bash
npm install @gitbook/api
```

### Initialize

Initialize the client with your [developer token](/docs/developers/integrations/quickstart.md#create-a-personal-access-token):

```typescript
import { GitBookAPI } from '@gitbook/api';

const client = new GitBookAPI({
  authToken: <your_access_token>
});
```

#### Node.js

If you use Node.js earlier than version 18, pass a custom `fetch` function. You can install one with [`node-fetch`](https://github.com/node-fetch/node-fetch):

```typescript
import { GitBookAPI } from '@gitbook/api';
import fetch from 'node-fetch';

const client = new GitBookAPI({
  customFetch: fetch
});
```

The client groups methods by GitBook resource.

### Search

Methods on `client.search`:

* `searchContent()`
* `askQuery()`

### User and users

Methods on `client.user`:

* `getAuthenticatedUser()`
* `listSpacesForAuthenticatedUser()`

Methods on `client.users`:

* `getUserById()`

### Spaces

Methods on `client.spaces`:

* `getSpaceById()`
* `searchSpaceContent()`
* `askQueryInSpace()`
* `importGitRepository()`
* `exportToGitRepository()`
* `getContentAnalyticsForSpaceById()`
* `getSearchAnalyticsForSpaceById()`
* `getTrafficAnalyticsForSpaceById()`
* `trackViewInSpaceById()`
* `getCurrentRevision()`
* `importContent()`
* `listFiles()`
* `getPageById()`
* `importContentInPageById()`
* `getPageByPath()`
* `createChangeRequest()`
* `mergeChangeRequest()`
* `updateChangeRequest()`
* `getRevisionOfChangeRequestById()`
* `importContentInChangeRequest()`
* `listFilesInChangeRequestById()`
* `getPageInChangeRequestById()`
* `importContentInChangeRequestPageById()`
* `getPageInChangeRequestByPath()`
* `getRevisionById()`
* `listFilesInRevisionById()`
* `getPageInRevisionById()`
* `getPageInRevisionByPath()`
* `listPermissionsAggregateInSpace()`

### Collections

Methods on `client.collections`:

* `getCollectionById()`
* `listSpacesInCollectionById()`
* `listPermissionsAggregateInCollection()`

### Integrations

Methods on `client.integrations`:

* `listIntegrations()`
* `getIntegrationByName()`
* `publishIntegration()`
* `unpublishIntegration()`
* `listIntegrationInstallations()`
* `listIntegrationSpaceInstallations()`
* `renderIntegrationUiWithGet()`
* `renderIntegrationUiWithPost()`
* `updateIntegrationInstallation()`
* `createIntegrationInstallationToken()`
* `updateIntegrationSpaceInstallation()`

### Organizations

Methods on `client.orgs`:

* `listOrganizationsForAuthenticatedUser()`
* `listMembersInOrganizationById()`
* `getMemberInOrganizationById()`
* `updateMemberInOrganizationById()`
* `removeMemberFromOrganizationById()`
* `setUserAsSsoMemberForOrganization()`
* `listSpacesForOrganizationMember()`
* `listTeamsInOrganizationById()`
* `createOrganizationTeam()`
* `getTeamInOrganizationById()`
* `updateTeamInOrganizationById()`
* `removeTeamFromOrganizationById()`
* `updateMembersInOrganizationTeam()`
* `listTeamMembersInOrganizationById()`
* `addMemberToOrganizationTeamById()`
* `deleteMemberFromOrganizationTeamById()`
* `inviteUsersToOrganization()`
* `joinOrganizationWithInvite()`
* `upgradeOrganizationPlan()`
* `getOrganizationBillingPortal()`
* `requestOrganizationUpgrade()`
* `transferOrganization()`
* `searchOrganizationContent()`
* `listSpacesInOrganizationById()`
* `listCollectionsInOrganizationById()`
* `setupDirectorySync()`
* `listDirectorySyncGroups()`
* `syncDirectorySyncGroupsToTeams()`

### URLs

Methods on `client.urls`:

* `getContentByUrl()`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/developers/integrations/development/client-library.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
