Sony XB950B1

Update wiki page of tfs by calling rest-api –

Application Programming Interface (API) Problem:

I would like to update an existing tfs wiki page with this document:

Creating a new wiki page (with content) is no problem at all. I’m fine. I’m fine.
However, I would like to modify an existing document. The tfs documentation indicates that the only difference in the API call is the use of the if-match header (see section Request Headers).

I have three situations here:

I think the revision hash (40 characters) is a good way to proceed, since an error message will result in an error of 400 for non40 hashes.

But it didn’t work? Does anyone know what this organization wants? I used the postman and C# to update the api. My sample code is below:

var handler = new HttpClientHandler()
UseDefaultCredentials = true,
UseProxy = false,

var client = new HttpClient(handler);
client.BaseAddress = new Uri(…/pages/page name + ?api version=4.1);
client.DefaultRequestHeaders.Accept.add(new System.Net.Http.Headers.MediaTypeMetQualityHeaderValue(application/json))

var putContent = new StringContent({content: new content for the page }, Encoding.UTF8, application/json) ;

client.DefaultRequestHeaders.TryAddWithoutValidation(If-Match, 09f62be600a3b6d36d21b294dbb00921a5ba03ec) ;

var responseTask = client.putAsync(client.baseAddress, putContent) ;

var result = responsTask.Result;
var content = result.Content.ReadAsStringAsync().Result ;

var body = content ;

How do you solve the API problem?

According to the Create or Update Wiki API, if we want to edit a wiki page, we need an if-match header. If-matchth-value is a page of the wiki ETag.

ETags can also be used for optimistic control of the competition to prevent funds from being transferred at the same time.

So we need to check the Etag wiki before we update it. Try changing the code as follows:

var baseUrl = xxxxx ;
var handler = new HttpClientHandler()
UseDefaultCredentials = true,
UseProxy = false,

var client = new HttpClient(handler)
BaseAddress = new Uri(baseUrl)
} ;
client.defaultRequestHeaders.Accept.add(new MediaTypeMetQualityHeaderValue(application/json)) ;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue (Basic, YourToken);
var getResult = client.GetAsync(baseUrl).Result;
var etag = getResult.Headers.GetValues(ETag);
var putContent = new StringContent({ content: new content for page }, Encoding.UTF8, application/json);
client.DefaultRequestHeaders.TryAddWithoutValidation(If-Match, etag);
var responseTask = client.PutAsync(client.BaseAddress, putContent);
var result = responseTask.Result;
var content = result.Content.ReadAsStringAsync().Result ;

Test result:

Give here a description of the image

Good luck!

Related Tags:

azure devops wiki,azure devops github pages,azure devops wiki api