4

I am trying to use the TeamCity API to retrieve build data in JSON format to show in a real-time display.

The display is a simple JavaScript application, served up as a web-page on a different domain to the TeamCity server. Therefore this has to be handled as a cross origin request (CORS).

My problem is that I cannot find a way of configuring a jQuery ajax request to both handle CORS and ask TeamCity to return a JSON response (rather than an XML response).

I've tried various combinations of settings in my ajax object, with the last version below:

    return $.ajax({
       url: url,
       dataType: "jsonp",
       /*accepts: "application/json",*/
       type: "GET",
       xhrFields: {
           withCredentials:true
       },
       beforeSend: function(xhrObj){
           xhrObj.setRequestHeader("Accept","application/json");
        }
     });

The "url" includes the login credentials for TeamCity, to satisfy the Http Authentication.

The response I get is the data I want, but in XML format (details of Request & Response headers below).

So my question is how to configure the ajax request to get JSON back from TeamCity?

Request URL:https://xxxxx/**httpAuth/app/rest/projects**?    
callback=jQuery210040475526987574995_1394042043670&_=1394042043671
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:__test=1; TCSESSIONID=F409E3C78BD3649E4DCA846DF5DD97F2;           
RememberMe=-116716355^12#-8135087298707329913
Host:builds.quillpinpoint.co.uk
Referer:http://localhost/orqaadmin/BuildMonitor/Index
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) 
Chrome/33.0.1750.146 Safari/537.36
Query String Parametersview sourceview URL encoded
callback:jQuery210040475526987574995_1394042043670
_:1394042043671
Response Headersview source
Cache-Control:no-store
Content-Length:1009
Content-Type:application/xml
Date:Wed, 05 Mar 2014 17:55:41 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Pragma:no-cache
Server:Microsoft-IIS/7.5
Set-Cookie:RememberMe=-xxxx
X-Powered-By:ARR/2.5
X-Powered-By:ASP.NET
Appetere
  • 6,003
  • 7
  • 35
  • 46

1 Answers1

2

On the TeamCity server, log in, Administration, Server Administration, Diagnostics, Internal Properties, Edit internal properties and add:

rest.cors.origins=*

This will add all sites. You can add a comma separated list of sites.

v8 https://confluence.jetbrains.com/display/TCD8/REST+API#RESTAPI-CORSSupport

v9 https://confluence.jetbrains.com/display/TCD9/REST+API#RESTAPI-CORSSupport

Zymotik
  • 6,412
  • 3
  • 39
  • 48