Create 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" }
- 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: - query—Returns data that hasn’t been deleted or archived. For more information, see query() in SOAP API Developer Guide.
- 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.
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.columnDelimiter parameter specifies what character to use. The actual separator can be a character other than a comma. TheOptional columnDelimiter The column delimiter used for CSV job data. The default value is COMMA. Possible values are: - BACKQUOTE—back quote character (`)
- CARET—caret character (^)
- COMMA—comma character (,)
- PIPE—pipe character (|)
- SEMICOLON—semicolon character (;)
- TAB—tab character
Optional lineEnding The line ending used for CSV job data, marking the end of a data row. The default is LF. Possible values are: - LF—linefeed character
- CRLF—carriage return character followed by a linefeed character
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:- UploadComplete—The job is ready to be processed and Salesforce has put the job in the queue.
- InProgress—Salesforce is processing the job.
- Aborted—The job has been aborted. See Abort a Query Job.
- JobComplete—Salesforce has finished processing the job.
-
Failed—The job failed.
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. 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"
}