0

I can't create new repositoies in bitbucket cloud with code below.

I'm able to delete repositiries (with change form 'post' to 'delete' requests method). When I'm using code below I've got http 400 which means according to api docs - If the input document was invalid, or if the caller lacks the privilege to create repositories under the targeted account.

import requests

username = 'user@mail.com'
password = 'password'


headers = {"Content-Type": 'application/json'}
auth = (username, password)
bb_base_url = f"https://api.bitbucket.org/2.0/repositories/username/reponame"

res = requests.post(bb_base_url, headers=headers, auth=auth)

print(res)

So would like to ask for help to refactor code in way I will be able to do two things

Maciej
  • 1,209
  • 4
  • 16
  • 26
  • 400 means bad request, check your json before posting – R4444 Aug 06 '19 at 05:26
  • Are you using reponame or repo_slug? – Piotr Kamoda Aug 06 '19 at 05:29
  • @ Ruturaj I'm green so I hardly know what to change in json... would not ask if knew – Maciej Aug 06 '19 at 06:54
  • @Piotr - yes I'm using repo name, for example 'test' – Maciej Aug 06 '19 at 06:55
  • According to REST API documentation you should use repo_slug there – Piotr Kamoda Aug 06 '19 at 06:59
  • I'm using word 'test' so no brainer for slug here... it will be the same. One of the anwsers from Atlassian forums by Atalssian team member: You can find the repo-slug in the URL for your repository. For example in one of my test repositories, documentation-tests, the URL is: https://bitbucket.org/teamsinspace/documentation-tests Teamsinspace is the owner, and documentation-tests is the repo slug. There is definetly something worng with Jason as Ruturaj mentioned but have no idea what... – Maciej Aug 06 '19 at 07:21
  • have you [authenticated](https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication) before? – Piotr Kamoda Aug 06 '19 at 10:04
  • If the same code allow me to delete repo I dont think (of course maybe I'm wrong) extra auth is needed... – Maciej Aug 06 '19 at 11:56
  • maybe that's a bug… I remember when I sent some rest request to bitbucket that I used this authentication. Worth a try? – Piotr Kamoda Aug 06 '19 at 13:20
  • Sure why not :) – Maciej Aug 06 '19 at 16:49
  • So the bug was simple - in requests syntaxt, was missing json part – Maciej Aug 06 '19 at 18:08

0 Answers0