Query Objects in Marketing Cloud Next Using REST API

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.

1GET /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
2Host: YOUR_SUBDOMAIN.my.salesforce.com
3Content-Type: application/json
4Authorization: Bearer YOUR_BEARER_TOKEN

If the request is successful, the response includes a list of contacts that match your query.

1{
2    "totalSize": 5,
3    "done": true,
4    "records": [
5        {
6            "attributes": {
7                "type": "Contact",
8                "url": "/services/data/{apiVersion}/sobjects/Contact/003AA000002ZZZDYAS"
9            },
10            "Id": "003SB000002L13DYAS",
11            "FirstName": "Jon",
12            "LastName": "Amos",
13            "MailingCountry": "NG"
14        },
15        ...
16    ]
17}