I'm able to fork a repository from postman with the following url : https://api.bitbucket.org/2.0/repositories/agencyName/repositoryName/forks and the body data.Unfortunately it doesn't work when I'm running the exact same request in my node.
My node statusCode response is a 400 and my body response is the following :
{"type": "error", "error":
{"fields":
{
"name": ["You already have a repository with this name."]},
"message": "Repository with this Slug and Owner already exists."
}
}
which is weird because there is no existing repository with the wanted fork repository name pass in the body.
The authentification process is ok. I'm able to process other requests from my node without issue.
Here is the code.
const BASE_URL_BITBUCKET = 'https://api.bitbucket.org/2.0/';
const RESOURCE = 'repositories/';
const WORKSPACE = 'agencyName/';
const = REPOSITORY: 'repositoryName/';
const = FORKS: 'forks';
const oauth = OAuth({
consumer: {
key: CONSUMER_KEY,
secret: CONSUMER_SECRET
},
signature_method: 'HMAC-SHA1',
hash_function(base_string, key) {
return crypto
.createHmac('sha1', key)
.update(base_string)
.digest('base64');
}
});
const forkRepository = forkRepositoryName => {
const REPOSITORY_NAME = forkRepositoryName.toLowerCase();
const request_data = {
url: `${BASE_URL_BITBUCKET}${RESOURCE}${WORKSPACE}${REPOSITORY}${FORKS}`,
method: 'POST',
body: { name: 'fork-1', is_private: true, workspace: { slug: WORKSPACE } },
json: true
};
return request(
{
url: request_data.url,
method: request_data.method,
form: oauth.authorize(request_data)
},
(error, response, body) => {
console.log('==> response : ', response.statusCode); //400 output
});
};
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.