TF400813: Resource not available for anonymous access error observed when accessing TFVC apis

  • Thread starter Thread starter newbiedevops
  • Start date Start date
N

newbiedevops

Guest
Hi,

I am trying to use the VSTS - TFS Rest API in order to be able to edit existing files in TFS, programmatically.

[Inspired by the Github Samples @ Microsoft/vsts-dotnet-samples]

This TFS API request works via postman and updates the file as expected.

API Being Used : http://tfsurl/tfscollection/_apis/tfvc/changesets?api-version=4.1
-------------------
Sample Request

----------------------

{

"Changes":[

{

"Item":{

"version":#versionnumber,

"Path":"$/project/Folder1/Folder2/Folder3/Samplefile.txt",

"ContentMetadata":{

"encoding":1200,

"contentType":"text/plain"

}

},

"ChangeType":2,

"NewContent":{

"Content":"Hello there!"

}

}

],

"Comment":"(sample) Adding a file which we'll later edit"

}

When invoking the same api through my vsts solution it appears to revert with the following error

Error Observed: TF400813: Resource not available for anonymous access. Client authentication required.


-----Code Snippet Tried so far through VSTS---------------------------------------------------------

using Microsoft.TeamFoundation.SourceControl.WebApi



var httpWebRequest =

(HttpWebRequest)WebRequest.Create("http://{tfsserverurl}/{tfscollection}/{tfsprojectname}/_apis/tfvc/changesets?api-version=4.1");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Accept = "application/json";

httpWebRequest.Method = "POST";
httpWebRequest.Credentials = new NetworkCredential(username, password, Domain);
string path = "Folder1/Folder2/Folder3/samplefile.txt";

jsonrequest = "{\"Changes\":[{\"Item\":{\"version\": 1234567,\"Path\":" + "\""+ path + "\"" + ",\"ContentMetadata\":{\"encoding\":1200,\"contentType\":\"text/plain\"}},\"ChangeType\":2,\"NewContent\":{\"Content\":\"Hello there!\" } }],\"Comment\":\"(sample) Adding a file which we'll later edit\"}";


using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(jsonrequest);
streamWriter.Flush();
streamWriter.Close();
}



var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd().ToString();

// return result;
}

Appreciate any guidance I can receive here.

Thanks!!

Continue reading...
 
Back
Top