I'm trying to update the content of an existing snippet via the API (using Python requests). I've written plenty of other automation, but this endpoint is giving me trouble. Probably because I'm not doing multipart form-data part correctly.
import os
import requests
import json
# Authenticate
token_response = requests.post(
url="https://bitbucket.org/site/oauth2/access_token",
auth=(f"{BITBUCKET_KEY}", f"{BITBUCKET_SECRET}"),
data={"grant_type":"client_credentials"}
).json()
access_token = token_response['access_token']
# Update
url = f"https://api.bitbucket.org/2.0/snippets/{workspace}/{encode_id}"
headers = {
"Accept": "application/json",
"Content-Type": "multipart/form-data",
"Authorization": f"Bearer {access_token}"
}
files = {'my-file.md': open('my-file.md','rb')}
response = requests.request(
"PUT",
url,
headers=headers,
files=files
)
if response.status_code != 200:
print(f"Got HTTP {response.status_code} on snippet write: {response.text}")
exit(2)
And the API is returning `Bad Request (400)` without any further context. Any ideas what I'm doing wrong?