Reputation: 129
Ok so I've read multiple articles on my topic but none seem to help. I'm trying to accomplish the same thing this guy wanted in this article here. I used the example stated in the answer (https://{yourserver}/defaultcollection/_apis/git/repositories?api-version=1.0 ) in an angular http get request but I'm getting a 401 error saying the credentials i supplied were not valid.
I then downloaded curl and supplied the following command "curl -u username:password http://{myserver}/defaultcollection/_apis/git/repositories?api-version=1.0" and the result came back the same, html saying i do not have valid credentials. Can someone point me in the right direction so I can pull the projects root branch and childrens branches and data along with it?
Essentially I am searching for a way to pull data from the server and display it on my web app. I'll need branches names and history for each branch and child branch.
Update
So I'm now able cURL into this service using the --ntlm switch that Richard recommended. Now to actually get my app connected to the service I found that I could pass windows credentials using:
withCredentials:true
It no longer gives me a 401 error. Instead I am not getting a new error stating:
XMLHttpRequest cannot load http://{servername}/{defaultcollection}/_apis/projects?api-version=1.0. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
What are my next steps to get this working?
Solution
I took what Richard suggested and created my own asp.net web api to communicate with tfs. I was able to modify the web.config file to allow CORS. I added the following lines to the system.webServer section of the file.
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
Doing this has resolved the error message I was receiving and creating a simple api to get specific information was not too hard to do. Thanks for all the help.
Upvotes: 3
Views: 1931
Reputation: 12546
In your curl command add --ntlm
as an option.
The command should be as follows:
curl -u username:password --ntlm http://{myserver}/defaultcollection/_apis/git/repositories?api-version=1.0
Be aware that the API doesn't currently support CORS. This means you can make API calls from your own server side code without a problem, but you can't make the calls directly from a browser. There's a UserVoice suggestion to enable this that you can vote for.
Upvotes: 5