GET Service Response Data
The REST web service returns data in XML or JSON format depending on the Accept and Content-type header parameters you use. For details, see
HTTP Request Header Parameters for operations supported in
OneData .
The service transforms data, as needed, so that it adheres to the XML structure, including making the following transformations:
Escapes all special characters in the response data.
Replaces spaces in object names and column captions with an underscore (_) character.
The GET REST service returns the XML/JSON Element Name property instead of the column name when the XML/JSON element name is defined in the column definition or foreign key constraint definition.
You can control whether OneData wraps rows in a <datarow> tag in the response , using the request parameter, baseVersion. Set baseVersion to true to generate XML output without datarows. By default, baseVersion is set to false, which returns the response data wrapped within datarows. Refer to the following XML examples of XML records wrapped within datarows.
The following code sample provides an example of XML output from the EMPLOYEE data object with datarows. In this example, EMPLOYEE is the physical object name, The remaining attributes use the XML element name. Each record is wrapped within a datarow tag.
<?xml version="1.0"?>
<EMPLOYEE>
<datarow>
<EMPLOYEE_ID>2012</EMPLOYEE_ID>
<EMPLOYEE_NAME>John Doe</EMPLOYEE_NAME>
<EMPLOYEE_DOB>1984-12-31 00:00:00.000000000</EMPLOYEE_DOB>
<EMPLOYEE_ADDRESS>H12,Brian Ave,California</EMPLOYEE_ADDRESS>
</datarow>
</EMPLOYEE>
In the next XML output sample, STATE-CITY is a conceptual object. The State and City records are wrapped within datarows.
<?xml version="1.0"?>
<STATE>
<datarow>
<ID>6</ID>
<NAME>New Jersey</NAME>
<CITY>
<datarow>
<ID>245</ID>
<NAME>Hackensack</NAME>
<POPULATION>50667</POPULATION>
</datarow>
<datarow>
<ID>453</ID>
<NAME>Cedar Falls</NAME>
<POPULATION>27083</POPULATION>
</datarow>
</CITY>
</datarow>
</STATE>
Response Examples
Example 1: GET operation response in XML format
The following is an example of OneData response to a GET request with the Accept header and content-type as application/xml.
<?xml version="1.0"?>
<COUNTRY>
<datarow>
<COUNTRY_ID>10</COUNTRY_ID>
<COUNTRY_NAME>SRILANKA</COUNTRY_NAME>
<STATE>
<datarow>
<STATE_ID>10</STATE_ID>
<STATE_NAME>COLOMBO</STATE_NAME>
<CONSTRAINT_COUNTRY_STATE>SRILANKA</CONSTRAINT_COUNTRY_STATE>
</datarow>
</STATE>
</datarow>
<datarow>
<COUNTRY_ID>1</COUNTRY_ID>
<COUNTRY_NAME>INDIA</COUNTRY_NAME>
<STATE>
<datarow>
<STATE_ID>1</STATE_ID>
<STATE_NAME>KARNATAKA</STATE_NAME>
<CONSTRAINT_COUNTRY_STATE>INDIA</CONSTRAINT_COUNTRY_STATE>
</datarow>
</STATE>
</datarow>
</COUNTRY>
Example 2: GET operation response in JSON format
The following is an example of OneData response to a GET request with the Accept header and content-type as application/json.
{
"COUNTRY": [
{
"COUNTRY_ID": "10",
"COUNTRY_NAME": "SRILANKA",
"STATE": [
{
"STATE_ID": "10",
"STATE_NAME": "COLOMBO",
"CONSTRAINT_COUNTRY_STATE": "SRILANKA"
}
]
},
{
"COUNTRY_ID": "1",
"COUNTRY_NAME": "INDIA",
"STATE": [
{
"STATE_ID": "1",
"STATE_NAME": "KARNATAKA",
"CONSTRAINT_COUNTRY_STATE": "INDIA"
}
]
}
]
}
Retrieving Columns from a Foreign Key Relationship
When you are working with related tables, you can retrieve the related columns. The State object contains a foreign key relationship to the Country object through the CNTRY_ID (where CNTRY_ID is the primary key, ID, in the Country object). In the Country object, the NAME column is the description corresponding to the ID. The XML/JSON element name for the NAME column in the Country object is COUNTRY_NAME. The following table summarizes this information.
Object Name | Column Name | XML Element Name for the Column |
State | ID | STATE_ID |
NAME | STATE_NAME |
CNTRY_ID | COUNTRY_ID |
Country | ID (Primary Key) | COUNTRY_ID |
NAME | COUNTRY_NAME |
You can also define an XML/JSON element name in the foreign key constraint. Therefore the XML/JSON element name for the foreign key constraint to the NAME column in the Country object could be Country_XML_Name.
Retrieving the State Object Using a RESTful Web Service
The following output is returned when a REST service retrieves the State object. Note that the XML/JSON element name used for the NAME column of the Country object is the XML/JSON element name defined in the foreign key constraint.
<?xml version="1.0" encoding="utf-8" ?>
<State>
<datarow>
<STATE_ID>3001</STATE_ID>
<STATE_NAME>State1</STATE_NAME>
<COUNTRY_XML_NAME>Country1</COUNTRY_XML_NAME>
</datarow>
<datarow>
<STATE_ID>5001</STATE_ID>
<STATE_NAME>State2</STATE_NAME>
<COUNTRY_XML_NAME>Country2</COUNTRY_XML_NAME>
</datarow>
</State>
In the next example of the REST service output, the related description column is the ID column in the Country object. In this case, the XML/JSON element name is the one defined for the ID in the Country object (Country.ID), not the XML/JSON element name of the foreign key constraint.
<?xml version="1.0" encoding="utf-8" ?>
<State>
<datarow>
<STATE_ID>3001</STATE_ID>
<STATE_NAME>State1</STATE_NAME>
<COUNTRY_ID>Country1</COUNTRY_ID>
</datarow>
<datarow>
<STATE_ID>5001</STATE_ID>
<STATE_NAME>State2</STATE_NAME>
<COUNTRY_ID>Country2</COUNTRY_ID>
</datarow>
</State>