Querying Salesforce using SOQL

Code

Before getting started make sure to set your Polytomic API key as an environment variable:

$export POLYTOMIC_API_KEY=YOUR-API-TOKEN

This example tutorial will cover three steps:

  1. Connecting to Salesforce.
  2. Executing a SOQL query on your Salesforce instance.
  3. Reading the results of your query from Polytomic.

1. Create a Salesforce connection

The following request will create a Salesforce connection. The configuration for each type of connection can be found at the connection configuration page.

$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"}}'

Since Salesforce connections use OAuth to authenticate, we’ll need to follow the link returned in the auth_url parameter in the response

Redirection


By default, the API expects the auth_url to be opened in a new browser window. If you’d like to modify the redirect behavior, there is an optional redirect_url parameter that can be added to the request body.

2. Start a SOQL query

THe following request will start a SOQL query on your Salesforce instance. The query will be executed and the results will be available via the Polytomic API.

$ 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. Reading query results

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