Create a Data Service Query: Example
The following steps walk you through the process of creating a data service query.
Step 1: Determine which table you need to receive data from.
To see the supported tables, send a request to the tables endpoint.
http://<host>:<port>/data/rest/dataservice/tables
Step 2: Determine which columns you need from that table.
To see the available columns, send a request to the columns endpoint.
http://<host>:<port>/data/rest/dataservice/columns/<tablename>
Step 3: Create your query.
Now that you have the table name and column names, you can create your query request. See the following examples.
Example 1
Request
For this request, we are assigning it a name of Project Data and a page size of 3. We are requesting the columns ABBREVIATION, CREATED, and CURRENCY from the PROJECTS table.
{ "name":"Project Data", "pageSize":"3", "tables":[ { "tableName":"PROJECTS", "columns":[ "ABBREVIATION", "CREATED", "CURRENCY" ] } ] }
Response
In the response to the request, 3 objects are received, respecting the defined pageSize, from the PROJECTS table each containing their respective values for the requested columns. In this example, the pagination data indicates that there is no more data in the response that has not been returned.
{ "data": { "PROJECTS": [ { "ABBREVIATION": "P1", "CREATED": "20180618T141232.847Z", "CURRENCY": "USD" }, { "ABBREVIATION": "P2", "CREATED": "20180618T141229.663Z", "CURRENCY": "USD" }, { "ABBREVIATION": "P3", "CREATED": "20180618T141230.387Z", "CURRENCY": "USD" } ], "pagination": [ { "nextTableName": "-1", "nextKey": "0" } ], "safetyDate": [ { "queryName": "Project Data", "sinceDate": "20180709T064616.000Z" } ] } }
Example 2
Request
For this request, we are assigning it a name of Contacts Data and a page size of 5. We are requesting the columns CONTACT_ID, CONTACT_OWNER_ID, CREATED, EMAIL_ADDRESS, and FIRST_NAME from the CONTACTS table.
{ "name":"Contacts Data", "pageSize":"5", "tables":[ { "tableName":"CONTACTS", "columns":[ "CONTACT_ID", "CONTACT_OWNER_ID", "CREATED", "EMAIL_ADDRESS", "FIRST_NAME" ] } ] }
Response
In the response to the request, 5 objects are received, respecting the defined pageSize, from the CONTACTS table each containing their respective values for the requested columns. In this example, the pagination data indicates that there is more data in the response that has not been returned. To receive the next chunk of data, the pagination data can be included in the next request.
{ "data": { "CONTACTS": [ { "CONTACT_ID": "1", "CONTACT_OWNER_ID": "0", "CREATED": "20170710T144110.057Z", "EMAIL_ADDRESS": "john.smith@example.com", "FIRST_NAME": "John" }, { "CONTACT_ID": "2001", "CONTACT_OWNER_ID": "1", "CREATED": "20170710T144110.295Z", "EMAIL_ADDRESS": "diane.jackson@example.com", "FIRST_NAME": "Diane" }, { "CONTACT_ID": "2002", "CONTACT_OWNER_ID": "0", "CREATED": "20170710T144110.570Z", "EMAIL_ADDRESS": "jeff.brown@example.com", "FIRST_NAME": "Jeff" }, { "CONTACT_ID": "2003", "CONTACT_OWNER_ID": "0", "CREATED": "20170710T144110.779Z", "EMAIL_ADDRESS": "cindy.johnson@example.com", "FIRST_NAME": "Cindy" }, { "CONTACT_ID": "6001", "CONTACT_OWNER_ID": "0", "CREATED": "20170710T152109.050Z", "EMAIL_ADDRESS": "mark.miller@example.com", "FIRST_NAME": "Mark" } ], "pagination": [ { "nextTableName": "CONTACTS", "nextKey": "6002" } ], "safetyDate": [ { "queryName": "Contacts Data", "sinceDate": null } ] } }