Querying Salesforce using SOQL

Code

Set your Polytomic API key as an environment variable:

$export POLYTOMIC_API_KEY=YOUR-API-TOKEN

This example covers three steps:

  1. Create a Salesforce Connection.
  2. Run a SOQL query on that Connection.
  3. Read the query results from Polytomic.

1. Create a Salesforce connection

The following request creates a Salesforce Connection. See the Salesforce connection configuration for the required fields.

$curl --request POST \
> --url https://app.polytomic.com/api/connections \
> --header "accept: application/json" \
> --header "content-type: application/json" \
> --header "X-Polytomic-Version: 2024-02-08" \
> --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \
> -d '{"name": "Salesforce Connection","type": "salesforce", "configuration": {"domain": "https://example.my.salesforce.com"}}'

Salesforce Connections authenticate with OAuth. Open the URL returned in the auth_url field of the response to complete the flow.

OAuth redirection

By default, the API expects auth_url to open in a new browser window. Set the optional redirect_url parameter in the request body to change the redirect target.

2. Start a SOQL query

The following request starts a SOQL query on the Salesforce Connection. The results are available through the Polytomic API once the query completes.

$ curl --request POST \
> --url https://app.polytomic.com/api/connections/SALESFORCE-CONNECTION-ID/query \
> --header "accept: application/json" \
> --header "content-type: application/json" \
> --header "X-Polytomic-Version: 2024-02-08" \
> --header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \
> -d '{
> "query": "SELECT Id, Name FROM Account"
> }'

3. Read the query results

Poll the query endpoint until the status is done or failed, then read the results:

$curl --request GET \
> --url https://app.polytomic.com/api/queries/QUERY_ID \
> --header "accept: application/json" \
> --header "Authorization: Bearer ${POLYTOMIC_API_KEY}"