Request Data With Query V2

Use the POST endpoint of Query API V2 to make the first request with the SQL query. The POST endpoint returns data along with batchId for the next batch.

A newer version of the Query API is available. We recommend using the newest Query API.

Note

Syntax 

  • HTTP Method: POST
  • Availability: Data 360 v2.0, Salesforce 54.0
  • format: REST
  • URI: /api/v2/query

Request Body 

The request body must contain a JSON object with these fields:

Field NameField TypeDescription
sqlstringThe SQL query to execute. Must be a valid ANSI standard SQL query.

Response Structure 

The response includes:

  • data: Array of record objects containing the requested data
  • startTime: ISO 8601 timestamp indicating when the query started executing
  • endTime: ISO 8601 timestamp indicating when the query finished executing
  • rowCount: Number of rows returned by the query
  • queryId: Unique identifier for the query
  • nextBatchId: Identifier for the next batch of results
  • done: boolean indicating if all results have been returned
  • metadata: Object containing metadata about the fields in the result set

Metadata Object 

The metadata object contains information about each field on the result set:

Field NameField TypeDescription
typestringSQL data type of the field
placeInOrderintegerPosition of the field on the result set
typeCodeintegerNumeric code representing the SQL data type

Examples 

Request 

1POST https://{TSE}.360a.salesforce.com/api/v2/query
2Authorization: Bearer {{cdpAuthToken}}
3Content-Type: application/json
4
5{
6  "sql": "select * from Orders__dll"
7}

Response 

1{
2  "data": [
3    [
4      "s3://dev1-uswest2-cdp001-test-data/sbothra/Orders.csv",
5      "aws",
6      null,
7      null,
8      "Office Supplies",
9      "0019-01-03",
10      null,
11      "Philadelphia",
12      "United States",
13      "MB-18085",
14      "Mick Brown",
15      "0.200000000000000000",
16      "570907236",
17      "0019-01-05 00:00:00.000 UTC",
18      "0019-01-05",
19      "CA-NEW-2014-141817",
20      "19143.000000000000000000",
21      "OFF-AR-10003478",
22      "Avery Hi-Liter EverBold Pen Style Fluorescent Highlighters 4/Pack",
23      "4.884000000000000000",
24      "3.000000000000000000",
25      "East",
26      "1760",
27      "19.536000000000000000",
28      "Consumer",
29      "0019-01-12 00:00:00.000 UTC",
30      "0019-01-12",
31      "Standard Class",
32      "Pennsylvania",
33      "Art"
34    ]
35  ],
36  "startTime": "2024-05-08T13:30:31.241168Z",
37  "endTime": "2024-05-08T13:30:35.571609Z",
38  "rowCount": 1,
39  "queryId": "20240508_133031_00088_p25a7",
40  "nextBatchId": "09151b49-54ed-4948-8139-1f4c7c3a9581",
41  "done": false,
42  "metadata": {
43    "state__c": {
44      "type": "VARCHAR",
45      "placeInOrder": 28,
46      "typeCode": 12
47    },
48    "sales__c": {
49      "type": "DECIMAL",
50      "placeInOrder": 23,
51      "typeCode": 3
52    },
53    "productid__c": {
54      "type": "VARCHAR",
55      "placeInOrder": 17,
56      "typeCode": 12
57    }
58  }
59}

Notes 

  • Use the done flag to determine if more results are available
  • When done is false, use the nextBatchId to retrieve the next set of records
  • All queries are executed synchronously
  • The API supports cursor-based pagination via nextBatchId
  • You must fetch the complete result set within one hour
  • The time interval between batch calls must not exceed three minutes

Related Resources