Customer 360 Audiences Query API Library

This API family supports only synchronous query API in v1, with SQL query in ANSI standard. The SQL can be a free form SQL with objects that include data streams, profile/engagement data model objects, and unified data model objects. This API can be used to support a variety of use cases that include data extraction, external application integration or interactive querying on the data lake.

Key Properties

  • The call return limit defaults to the max limit of 4999 rows returned.
  • There is no explicit limit to the SQL call length.
  • There is no explicit limit for the number of nested sub queries.
  • There is no explicit limit for the number of joins.
  • There is no explicit limit for the number of filters.
  • There is no explicit limit for the number of column projections.
  • There is no explicit limit for any specific data type, such as VARCHAR, DECIMAL, or TIMESTAMP.

Connected App Setup

Perform the following steps to set up a connected app, before using the calls in this section. Use Salesforce’s OAuth 2.0 JSON Web Token (JWT) bearer flow to acquire a token, as described in the steps below.

  1. Create a connected app.
  2. Enable OAuth settings on the connected app.
  3. Give a name/label.
  4. Locate your private/public key pair.
  5. If you don't have these, use the following steps:
    1. You need a .key and a .crt file (private and public key)
    2. Go to any folder and run the following commands:
      1openssl genrsa 2048 > host.key
      2                  chmod 400 host.key
      3                  openssl req -new -x509 -nodes -sha256 -days 365 -key host.key -out host.crt
      This command creates a host.key and a host.crt file in that folder.
  6. Specify any redirect_uri.
  7. Select the scopes required
    1. You must select refresh_token, and at least one other scope (Select api, for example).
  8. Save your changes so far. Copy your client ID and client secret so you can add it later.
  9. Go to the Manage page for the connected app and edit the following policies:
    1. Change Restrict IP to Relax IP restrictions.
    2. If you don't have any custom scopes, create them now.
    3. Choose Manage custom scopes and add cdpprofile and cdpquery to the custom scopes.
  10. Authorize the users for whom you are creating JWT bearer tokens.
    1. This is a one-time step for each user. If you don't perform this step, you receive a user hasn’t approved consumer error.
    2. Construct this URL
      1https://<ORG URL>/services/oauth2/authorize?response_type=code&client_id=<CLIENT ID>&scope=api refresh_token cdpprofile cdpquery&redirect_uri=https://oauth.pstmn.io/v1/callback
      1. Change redirect_url value if you are using
        1https://oauthdebugger.com
      2. Notice the scope parameter in the constructed URL. It’s important that you select all the required custom CDP scopes in this request. All further JWT bearer flow requests will only use these scopes.
  11. This prompts a consent dialog that asks you to give permission for each of the scopes you requested. Choose Allow for each of the scopes.
Your connected app is all setup and ready to go!

Acquire an Access Token

The following example shows you how to request an access token:
1POST https://login.salesforce.com/services/oauth2/token
2          
3          Content-Type: x-www-form-urlencoded
4          
5          grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer
6          &assertion=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiIzTVZHOUFPcDRrYnJpWk9JZmg0eWZPQVlQUjFpYzJqb1JDQkhwZFZtaXBXU05sbXNwT2Vib1VtcWdMdHJIcDlRVFRQMGpWc3g0SHlzUW4xLk1SazFyIiwic3ViIjoic3VkaGVlckBvcmdtYWluMi5jb20iLCJhdWQiOiJodHRwOi8vc3VrdW1hci1sdG0uaW50ZXJuYWwuc2FsZXNmb3JjZS5jb20iLCJleHAiOjE2MDQ2Mzc4MTkyNTd9.WkEcmaGj_jhJpyFqXwEUtw-bkeXYuxkqc2c3lkwbGjg3GDo7sStITht_O_dSNanS0xk2q9ARA6Uom-uaiyNw_GGGK5L3jBQjK-ytrGumuJAsujjfSmLdYStxPVnjU2zyuPSWMQJmeDegxDgmeht3UQyluj0q4lX3rayx0Ol-vZfTuzr4YlxmdOKTNrPJCQ8h26uMSPFrQmmqcssrSg1DRgm3kMh15VKM3yZyNAg43EPw1BfncPWIxOmsGt2JxUUclBER3enTLM2cJKr9fDx16Ssesj2UKqXGbwN68gCF5rZxD6yGN5B0VeZIZVJrY5cTtExqBp3Lj8UOcqUj6esyCQ
Response Format:
1{
2          "access_token": "00Dxx0000006JFr!AQEAQL7SvQ1t..2yYtyM0jfXtMNriivdMpTYE3mThqATnm5YqPIX.xnzUC45zd0HEIU3tc9GdHLqWOFVprsgszWdYMPRUnOy",
3          "scope": "cdpquery api cdpprofile",
4          "instance_url": "http://orgmain2.localhost.internal.salesforce.com:6109",
5          "id": "http://sukumar-ltm.internal.salesforce.com:6109/id/00Dxx0000006JFrEAM/005xx000001X9hBAAS",
6          "token_type": "Bearer"
7          }
Follow this link to create the assertion JWT: Create Assertion JWT

Exchange Your Access Token for a Customer 360 Audiences Token (CDP Token)

The following example shows you how to request a Customer 360 Audiences Token:
1POST <Instance URL>/services/a360/token
2          
3          Content-Type : x-www-form-urlencoded
4          
5          grant_type=urn:salesforce:grant-type:external:cdp
6          &subject_token=<CORE ACCESS TOKEN>
7          &subject_token_type=urn:ietf:params:oauth:token-type:access_token
Response Format:
1{
2          "access_token": "eyJraWQiOiJDT1JFLjAwRHh4MDAwMDAwNkpGci4xNjAzMjM5NzI2NjI5IiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJodHRwOi8vc3VrdW1hci1sdG0uaW50ZXJuYWwuc2FsZXNmb3JjZS5jb206NjEwOS9pZC8wMER4eDAwMDAwMDZKRnJFQU0vMDA1eHgwMDAwMDFYOWhCQUFTIiwiYXVkIjoiYTM2MCIsInNjcCI6ImNkcHByb2ZpbGUgY2RwcXVlcnkiLCJuYmYiOjE2MDQ1NTE3NzYsInNmb2lkIjoiMDBEeHgwMDAwMDA2SkZyIiwiaXNzIjoiaHR0cDovL3N1a3VtYXItbHRtLmludGVybmFsLnNhbGVzZm9yY2UuY29tOjYxMDkvIiwic2Z1aWQiOiIwMDV4eDAwMDAwMVg5aEIiLCJleHAiOjE2MDQ1NTkwMjgsImlhdCI6MTYwNDU1MTgzNiwianRpIjoiYjk1ODA1ZDUtM2MzYS00MDNkLWJiNjgtNjBkNTJlNmM4OTBjIiwic2ZhcHBpZCI6IjNNVkc5QU9wNGticmlaT0lmaDR5Zk9BWVBSMWljMmpvUkNCSHBkVm1pcFdTTmxtc3BPZWJvVW1xZ0x0ckhwOVFUVFAwalZzeDRIeXNRbjEuTVJrMXIifQ.GAWqiPpVJoDig-adGtD4d5cO7L7JaIn2mOYH9GyDD7oO7Ayrsnv_k05QRPp-B1gSd4U8lqE_cuC0MTE9L6lzJA",
3          "instance_url": "https://a360.cdp.cdp001.dev1-uswest2.aws.sfdc.cl",
4          "token_type": "Bearer",
5          "issued_token_type": "urn:ietf:params:oauth:token-type:jwt",
6          "expires_in": 7191
7          }
Use the access_token from the response as the instance_url, which is the Customer 360 Audiences (CDP) URL.

Refer to the following API documentation sections to interact with these query API calls.

Call Reference

POST /api/v1/query