Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

[400 response] - Bitbucket fork by api

mickaelandrepro
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 1, 2020 edited

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

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, bitbucket, ci/cd workflows, scale ci cd, bitbucket webinar, devops pipeline, continuous integration, continuous delivery, atlassian learning, software automation, developer tools, build and deploy, pipeline optimization, atlassian community

Scale CI/CD workflows faster with Bitbucket Pipelines 🪣

Join this webinar on June 25/26th to learn how to build secure CI/CD workflows using Bitbucket Pipelines and get tips from our own engineers on how to speed up builds and operate at scale.

Register today
AUG Leaders

Atlassian Community Events