Is there any way to update the contents of a file in a project on your visual studio team services account using HTTP verbs, similar to how it is done here with github https://developer.github.com/v3/repos/contents/#update-a-file.
var json={
"comment": "Update scripts.json",
"changes": [{
"changeType": 2,
"item": {
"path": "$/ExtensionsTest/scripts.json",
"contentMetadata": { "encoding": 65001 },
"version": 47
},
"newContent": {
"content": "[ {\"hello\" : \"Test\"} ]",
"contentType":"RawText"
}
}]
};
$.ajax({
type: 'POST',
url: 'https://xxxxx.visualstudio.com/_apis/tfvc/changesets?api-version=3.0-preview.2',
contentType: 'application/json',
data: JSON.stringify(json),
cache: false,
dataType: "json",
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("my UserName" + ":" + "my PW"));
}
}).done(function (data) {
console.log(data);
});
};
The code above is what I am using and I get a 400 error with it. Any suggestions on what I am doing wrong.
Try these ways:
If you are using GIT:
JSON data:
If you are using TFVC:
Json data:
Note: You need to parse quotes if file content contains quotes (\”test\”), the same as other special charters.
On the other hand, you can achieve that through vso-node-api, more information, you can refer to this thread: TFS Rest API check-in to Version Control
Update1:
Refer to this code to modify your code: