Response formats
Targetprocess REST API supports XML and JSON response formats. Default format is XML.
There are two options to set the response format:
Define format on the fly via the format URL parameter:
/api/v1/UserStories/35429?format=json
/api/v1/UserStories/35429?format=xml
Use HTTP header Accept to specify response format. For example, to retrieve response in JSON:
GET /api/v1/UserStories/ HTTP/1.1
Host: localhost
Accept: application/json
XML
All fields except Id and Name are returned as xml elements. Id and Name fields are returned as attributes. If a field is null, the corresponding xml element will have "nil" attribute set to "true".
Xml format uses ISO 8601 for date formatting.
<UserStory Id="376" Name="CRUD operations">
<Description nil="true" />
<CreateDate>2011-09-01T18:20:35</CreateDate>
</UserStory>
JSON
JSON formatting uses format "/Date(1198908717056+0300)/"
where the number is the number of milliseconds since January 1st 1970.
{
"Id": 376,
"Name": "CRUD operations",
"Description": null,
"CreateDate": "/Date(1314890435000+0300)/"
}
JSONP
Targetprocess REST API supports JSONP pattern. To return the JSON padded with your callback, use callback=functionName
query parameter.
/api/v1/UserStories/35429?format=json&callback=parseJson
parseJson({
"Id": 376,
"Name": "CRUD operations",
"Description": null,
"CreateDate": "/Date(1314890435000+0300)/"
});
Here is an example with help of jQuery. We extract all projects and show their names.
$.getJSON("/api/v1/projects?&format=json&callback=?", buildProjects);
function buildProjects(data) {
var projectNames = "";
for (i = 0; i < data.Projects.Items.length; i++) {
if (data.Projects.Items[i]) {
projectNames += data.Projects.Items[i].Name;
}
}
alert(projectNames);
}
Updated over 5 years ago