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');

Constructors

Methods

  • 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();
  • 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');