REST API provides a simple method for executing basic queries synchronously. If the complexity of the query or the quantity of results causes your queries to timeout, consider running them asynchronously using Bulk API 2.0.
Prerequisite
Before you issue a query request, create a SOQL statement that defines the data that you want to retrieve. For more information, see Understand SOQL Queries.
After you create a SOQL statement, remove all of the line breaks, and replace every space in the query with %20.
Issue the GET Request
Issue a GET request to the /services/data/{apiVersion}/query endpoint, with your SOQL query included as a query string.
GET /services/data/{apiVersion}/query/?q=SELECT%20Id,%20FirstName,%20LastName,%20MailingCountry%20FROM%20Contact%20WHERE%20MailingCountry%20=%20%27NG%27%20ORDER%20BY%20LastName%20ASC,%20FirstName%20ASC%20LIMIT%205 HTTP/1.1
Host: YOUR_SUBDOMAIN.my.salesforce.com
Content-Type: application/json
Authorization: Bearer YOUR_BEARER_TOKEN
If the request is successful, the response includes a list of contacts that match your query.
{
"totalSize": 5,
"done": true,
"records": [
{
"attributes": {
"type": "Contact",
"url": "/services/data/{apiVersion}/sobjects/Contact/003AA000002ZZZDYAS"
},
"Id": "003SB000002L13DYAS",
"FirstName": "Jon",
"LastName": "Amos",
"MailingCountry": "NG"
},
...
]
}