Creates a query job.
Syntax
URI: /services/data/vXX.X/jobs/query
Available since release:
This resource is available in API version 47.0 and later.
Format: application/json
HTTP method: POST
Authentication: Authorization:Bearer token
Headers: Optionally, use the Sforce-Call-Options header to specify a default namespace.
Request body
The request body specifies the query to be performed.
{
"operation": "query",
"query": "SELECT Id FROM Account"
}
note: Bulk API 2.0 doesn’t support SOQL queries that include any of these items:
- GROUP BY, OFFSET, or TYPEOF clauses.
- Aggregate Functions such as
COUNT(). - Date functions in GROUP BY clauses. (Date functions in WHERE clauses are supported.)
- Compound data, such as compound address fields, compound geolocation fields, and
FIELDS(). (Instead, query the individual components of compound fields.) - Parent-to-child relationship queries. (Child-to-parent relationship queries are supported.)
You can also specify some optional parameters. For example:
{
"operation" : "query",
"query" : "SELECT Id FROM Account",
"contentType" : "CSV",
"columnDelimiter" : "CARET",
"lineEnding" : "CRLF"
}
Request parameters:
| Parameter | Description | Required or Optional |
|---|---|---|
operation |
The type of query. Possible values are:<ul><li>query—Returns data that hasn’t been deleted or archived. For more information, see query() in SOAP API Developer Guide.</li><li>queryAll—Returns records that have been deleted because of a merge or delete, and returns information about archived Task and Event records. For more information, see queryAll() in SOAP API Developer Guide.</li></ul> |
Required |
query |
The query to be performed. | Required |
contentType |
The format to be used for the results. Currently the only supported value is CSV (comma-separated variables). Defaults to CSV. The actual separator can be a character other than a comma. The columnDelimiter parameter specifies what character to use. |
Optional |
columnDelimiter |
The column delimiter used for CSV job data. The default value is COMMA. Possible values are:<ul><li>BACKQUOTE—back quote character (`)</li><li>CARET—caret character (^)</li><li>COMMA—comma character (,)</li><li>PIPE—pipe character (|)</li><li>SEMICOLON—semicolon character (;)</li><li>TAB—tab character</li></ul> |
Optional |
lineEnding |
The line ending used for CSV job data, marking the end of a data row. The default is LF. Possible values are:<ul><li>LF—linefeed character</li><li>CRLF—carriage return character followed by a linefeed character</li></ul> |
Optional |
Response Body
{
"id" : "750R0000000zlh9IAA",
"operation" : "query",
"object" : "Account",
"createdById" : "005R0000000GiwjIAC",
"createdDate" : "2018-12-10T17:50:19.000+0000",
"systemModstamp" : "2018-12-10T17:50:19.000+0000",
"state" : "UploadComplete",
"concurrencyMode" : "Parallel",
"contentType" : "CSV",
"apiVersion" : 46.0,
"lineEnding" : "LF",
"columnDelimiter" : "COMMA"
}
Response Parameters:
| Parameter | Description |
|---|---|
id |
The unique ID for this job. |
operation |
The type of query. |
object |
The object type being queried. |
createdById |
The ID of the user who created the job. |
createdDate |
The UTC date and time when the job was created. |
systemModstamp |
The UTC date and time when the API last updated the job information. |
state |
The current state of processing for the job. Possible values are: <ul><li>UploadComplete—The job is ready to be processed and Salesforce has put the job in the queue.</li><li>InProgress—Salesforce is processing the job.</li><li>Aborted—The job has been aborted. See Abort a Query Job.</li><li>JobComplete—Salesforce has finished processing the job.</li><li>Failed—The job failed.</li></ul> |
concurrencyMode |
Reserved for future use. How the request is processed. Currently only parallel mode is supported. (When other modes are added, the API chooses the mode automatically. The mode isn’t user configurable.) |
contentType |
The format to be used for the results. Currently the only supported value is CSV. JunctionIdList fields and embedded lists can't be returned. |
apiVersion |
The API version that the job was created in. |
lineEnding |
The line ending used for CSV job data, marking the end of a data row. |
columnDelimiter |
The column delimiter used for CSV job data. |
Example
This example creates a job that queries Accounts.
curl --include --request POST \
--header "Authorization: Bearer token" \
--header "Accept: application/json " \
--header "Content-Type: application/json" \
--data '{
"operation": "query",
"query": "SELECT Id, Name FROM Account"
}' \
https://instance.salesforce.com/services/data/vXX.X/jobs/query
The response is:
HTTP/1.1 200 OK
{
"id" : "750R0000000zw4yIAA",
"operation" : "query",
"object" : "Account",
"createdById" : "005R0000000GiwjIAC",
"createdDate" : "2018-12-17T21:00:17.000+0000",
"systemModstamp" : "2018-12-17T21:00:17.000+0000",
"state" : "UploadComplete",
"concurrencyMode" : "Parallel",
"contentType" : "CSV",
"apiVersion" : 46.0,
"lineEnding" : "LF",
"columnDelimiter" : "COMMA"
}