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,
https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/src#post
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);
It looks like you're new here. Sign in or register to get started.