BB v7.2.0 LTS - PUT not allowed when trying to upload a file to a repo

Dear team Bitbucket,

Using the API, specifically REST Resources Provided By: Bitbucket Server - REST

Here is the code I’m using

import requests as req, json, sys
from urllib3 import encode_multipart_formdata

    net_pol = open(sys.argv[1]).read()
    "Could not open the network policy file. Exiting."

repo = sys.argv[2]

token = ""
branch = "netpol"

# print("net_pol file is:", net_pol,"repo is", repo)

payload = {'content': ("networkPolicy.yaml", net_pol), 'message': "Automatically synthesized policy using NP-Guard", "branch": branch, "sourceCommitId": ""}
data, boundary = encode_multipart_formdata(payload)

headers = {}
headers["Content-Type"] = boundary
headers["Authorization"] = f"Bearer {token}"

res = req.put(f"https://bitbucket.local:8443/projects/myproject/repos/{repo}/browse/helm-chart/templates/networkPolicy.yaml", data=data, headers=headers, verify=False)
if res.status_code != 201:
    print("Could not upload the policy.")

The server returns 405 for a POST request as well.

Similar to the issue 63377 from last year BUT I am using form data.

Please assist.

Thank you.

I realised that I missed the ReST URL “rest/api/1.0”. I tried with it as well - it is not possible to add the new content.

b'{"errors":[{"context":null,"message":"Network/tags-management-new.yaml could not be edited because the file has been deleted on the  branch.","exceptionName":"com.atlassian.bitbucket.content.NoSuchPathException"}]}'

Yes, it’s true - the file is not there. I need the server to create it.

I also tried different branches in case there’s an implicit protection of the main branch - doesn’t work.

Please assist.

From the way the server responds it is clear that PUT is only for editing, not for creating.

However, POST is not allowed.

Is it possible to upload a new file - has it been implemented?

Thank you