node-bitbucket icon indicating copy to clipboard operation
node-bitbucket copied to clipboard

Token Authorization doesn't seem to be working

Open sh-ghanique opened this issue 2 years ago • 2 comments

What am I doing wrong here?

Consider the following code:

import { Bitbucket } from "bitbucket";

const apiToken = 'Token as copied from https://id.atlassian.com/manage/api-tokens';
const bitbucket = new Bitbucket({
  baseUrl: 'https://api.bitbucket.org/2.0',
  auth: {
    token: apiToken,
  }
});

const repos = bitbucket.user.get({}).then(value => {
  console.log(value.data);
});

Steps to reproduce

  1. Go to https://id.atlassian.com/manage/api-tokens
  2. Create a new API token.
  3. Copy the API token
  4. In the code above replace "Token as copied from https://id.atlassian.com/manage/api-tokens'" with the API token.
  5. Run the code.

Expected

The current user is being logged.

Actual

BITBUCKET CLOUD API LATEST UPDATES:  https://developer.atlassian.com/cloud/bitbucket 
index.ts:11
Process exited with code 1
Uncaught i HTTPError: Unauthorized
    at <anonymous> (/wrk/bitbucket/node_modules/bitbucket/src/request/fetch-wrapper.ts:48:17)
    at processTicksAndRejections (internal/process/task_queues:95:5)

sh-ghanique avatar Aug 09 '23 22:08 sh-ghanique

Is that token for bitbucket or token for atlassian? Can you make api call without this library with that token?

MunifTanjim avatar Aug 10 '23 05:08 MunifTanjim

Same issue, having dug around and reading posts such as https://stackoverflow.com/questions/68597002/why-is-personal-access-token-not-working-for-bitbucket-rest-api it seems that bitbucket expects you to have both a token with a username. So I got it working by passing username and password=token

Brianzchen avatar Sep 11 '23 04:09 Brianzchen