Bitbucket Data Center API Client
    Preparing search index...

    Class BitbucketClient

    Main entry point for the Bitbucket Data Center REST API client.

    const bbClient = new BitbucketClient({
    apiUrl: 'https://bitbucket.example.com',
    apiPath: 'rest/api/latest',
    user: 'pilmee',
    token: 'my-token',
    });

    const projects = await bbClient.projects({ limit: 50 });
    const project = await bbClient.project('PROJ');
    const repos = await bbClient.project('PROJ').repos({ name: 'api' });
    const repo = await bbClient.project('PROJ').repo('my-repo');
    const prs = await bbClient.project('PROJ').repo('my-repo').pullRequests({ state: 'OPEN' });
    const commits = await bbClient.project('PROJ').repo('my-repo').commits({ limit: 10 });
    const users = await bbClient.users({ filter: 'john' });
    const user = await bbClient.user('pilmee');
    Index

    Constructors

    Methods

    • Searches for code across all repositories visible to the authenticated user, using Bitbucket's search query syntax (e.g. 'jwt project:PROJ ext:ts').

      POST /rest/search/latest/search

      Parameters

      • query: string

        The search query

      • Optionalparams: CodeSearchParams

        Optional paging for the code results: start, limit

      Returns Promise<CodeSearchResult>

      The search result, with code hits under code.values

      This is an internal Bitbucket UI endpoint, not part of Atlassian's public REST API specification. It may change or disappear between Bitbucket versions. The response is typed defensively — see CodeSearchResult.

      const result = await bbClient.codeSearch('parseWebhookEvent repo:my-repo');
      for (const hit of result.code?.values ?? []) {
      console.log(`${hit.repository.slug}: ${hit.file}`);
      }
    • Fetches the currently authenticated user.

      Bitbucket Data Center has no documented "whoami" endpoint, so this method resolves the username from the X-AUSERNAME header that Bitbucket attaches to every authenticated response, and then looks the user up via GET /rest/api/latest/users?filter={username} (two requests).

      Returns Promise<BitbucketUser>

      The authenticated user object

      If the authenticated user cannot be determined

      const me = await bbClient.currentUser();
      
    • Fetches the names of all groups visible to the authenticated user.

      GET /rest/api/latest/groups

      Parameters

      • Optionalparams: GroupsParams

        Optional filters: filter (group name prefix), limit, start

      Returns Promise<PagedResponse<string>>

      A paged response of group names (plain strings)

      const groups = await bbClient.groups({ filter: 'dev' });
      console.log(groups.values); // ['developers', 'devops']
    • Renders a preview of the given markup (e.g. Markdown) as HTML.

      POST /rest/api/latest/markup/preview

      The markup is sent as the raw request body (not JSON-encoded).

      Parameters

      • markup: string

        The raw markup to render

      • Optionalparams: MarkupPreviewParams

        Optional rendering options: urlMode, htmlEscape, includeHeadingId, hardwrap

      Returns Promise<MarkupPreviewResult>

      The rendered HTML

      const { html } = await bbClient.markupPreview('I am **bold**');
      
    • Subscribes to a client event.

      Type Parameters

      • K extends "request"

      Parameters

      Returns this

      bbClient.on('request', (event) => {
      console.log(`${event.method} ${event.url} — ${event.durationMs}ms`);
      if (event.error) console.error('Request failed:', event.error);
      });
    • Returns a ProjectResource for a given project key, providing access to project-level data and sub-resources.

      The returned resource can be awaited directly to fetch project info, or chained to access nested resources.

      Parameters

      • projectKey: string

        The project key (e.g., 'PROJ')

      Returns ProjectResource

      A chainable project resource

      const project = await bbClient.project('PROJ');
      const repos = await bbClient.project('PROJ').repos({ limit: 10 });
      const prs = await bbClient.project('PROJ').repo('my-repo').pullRequests();
    • Fetches repositories across all projects, mapping the documented GET /rest/api/latest/repos parameters 1:1 (no transformation is applied).

      The response is paginated (isLastPage, nextPageStart, values[]) and every repository embeds its project, so results spanning several projects can be filtered or grouped client-side by project.key.

      Note that projectname matches the project name partially and case-insensitively (not its key); when syncing across projects prefer projectkey or validate project.key on each result.

      Parameters

      • Optionalparams: GlobalReposParams

        Optional filters: name, projectkey, projectname, permission, visibility, state, archived, limit, start

      Returns Promise<PagedResponse<BitbucketRepository>>

      A paged response of repositories

      const page = await bb.repos({ name: 'orchestrator', permission: 'REPO_READ', limit: 100 });
      const byProject = Object.groupBy(page.values, (repo) => repo.project.key);
    • Returns a UserResource for a given user slug, providing access to user data.

      The returned resource can be awaited directly to fetch user info.

      Parameters

      • slug: string

        The user slug (e.g., 'pilmee')

      Returns UserResource

      A chainable user resource

      const user = await bbClient.user('pilmee');