I am building an API client, that uses bitbucket REST APIs, for a web application. I am building the API client in Node.js as shown in the Atlassian demo code.
When I test the API calls from POSTMAN vs my Node.js code, I am not getting the same results.
I have bitbucket user Id. On that user Id's profile I setup an oauth client. Generated a client Id and secret. I am using the "client credentials" oauth flow in POSTMAN and in my Node.js code. This client has read and write permissions on just about all of the areas.
Here is one example. When I call the below endpoint from POSTMAN, I get back two repos. One private and one public. This is correct. In the test environment that is all we have.
https://api.bitbucket.org/2.0/repositories/{username}?is_private=true
However when I run the same code in Node.js I only get back the public repo. Even with the querystring value added.
POSTMAN Request (Node.js code)
var request = require("request");
var options = { method: 'GET',
url: 'https://api.bitbucket.org/2.0/repositories/myUserNameHere',
qs: { is_private: 'true' },
headers:
{ 'cache-control': 'no-cache',
Connection: 'keep-alive',
'Accept-Encoding': 'gzip, deflate',
Host: 'api.bitbucket.org',
'Postman-Token': '146ac64',
'Cache-Control': 'no-cache',
Accept: '*/*',
'User-Agent': 'PostmanRuntime/7.17.1',
Authorization: 'Bearer o=',
'Content-Type': 'application/json' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
My Node.js code for the same request
getPrivateRepos: function(access_token, token_type) {
let options = {
method: "GET",
url: "https://api.bitbucket.org/2.0/repositories/myusername/",
qs: { is_private: "true"},
headers: {
"Cache-Control": "no-cache",
Authorization: `${token_type} ${access_token}`,
"Content-Type": "application/json"
}
};
request(options, function(error, response, body) {
if (error) throw new Error(error);
console.log("Get private repos -> " + response.statusCode,response.statusMessage);
console.log(body);
});
}