Hi,
I'm building a web based editor (in React) which needs to commit changes to our BitBucket repo. GET requests seem to working perfectly however the code below is returning a 415 error which I think relates to incorrect content/meta type..?
There's no mention of how to specify a meta type in the docs,
Is meta type the real problem here? or have I done something else wrong?
Can anyone help?
thanks
const url = new URL(`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo}/src`);
const params = {
access_token: query.access_token,
message: encodeURIComponent("commit"),
branch: branchName,
[encodeURIComponent(path + '/start.json')]: "helloWorld"
};
Object.entries(params).forEach(([key, value]) => {
url.searchParams.append(key, value)
});
fetch(url, { method: 'POST' }).then(handleResponse);
Here's the fix for anyone searching...
const url = new URL(`https://api.bitbucket.org/2.0/repositories/${workspace}${repo}src`);
url.searchParams.append('access_token', token);
const data = new URLSearchParams();
data.append('message', commitMsg);
data.append('branch', branchName);
data.append(path, fileContent);
const options = {
method: 'post',
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
body : data
}
fetch(url, options).then(handleResponse);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.