Skip to main content
Skip table of contents

Salesforce Contacts [REST OAuth 2.0]

PocketQuery allows you to connect directly to Salesforce’s REST API and query your CRM data with a wide range of objects, such as Contacts, Accounts, Opportunities, and Leads. You can use PocketQuery to fetch, filter, and explore this data just like any other data source.

In the examples below, we’ll demonstrate how to connect to the Contacts API. The same approach works for any other Salesforce object - simply adjust the endpoint URL accordingly. For detailed information on available endpoints and object types, refer to the Salesforce REST API documentation, where all available objects and their fields are listed.

Preview

Table with Contacts from Salesforce displayed in Confluence

Step 1 : Create a Developer Edition account

Create a Developer account in Salesforce if you haven't already: https://www.salesforce.com/form/developer-signup/?d=pb

Step 2: Set up a External Client App

Log in to your Salesforce Developer account and go to Settings > Setup:

Screen of Salesforce navigation with settings

Use the sidebar navigation to scroll down to Apps > External Client Apps > Settings and enable Allow access to External Client App consumer secrets via REST API:

Screen of Salesforces settings

In the sidebar go to Apps > External Client Apps > External Client App Manager and click the New External Client App button:

Screen of Salesforce Settings App Manager

Fill out the form:

Screen of Salesforce Settings when creating a new app

#

Field description

Value

1

External Client App Name

PocketQuery

API Name

Filled out automatically

2

Contact Email

Enter your Email

Distribution State

Keep “Local”

3

Logo Image URL (optional)

Use this link if you’d like the PocketQuery logo to be displayed

Scroll down to API (Enable OAuth Settings) and configure the following settings:

Screen of Salesforce Settings to enable API

#

Field description

Value

1

Enable OAuth

Tick checkbox

2

Callback URL

https://login.salesforce.com/

3

OAuth Scopes

Choose:

  • Manager user data via APIs (api)

  • Perform requests at any time (refresh_token)

Scroll down once more and untick Require Proof Key and click Create:

Screen of Salesforce Settings for creating new app

You will then be redirected to the overview of your newly created app. Click the Consumer Key and Secret button to receive your credentials. You will need them in Step 3.

Screen of App settings in Salesforce

Step 3: Create a Refresh Token

In this example, we’ll use Postman to obtain a Refresh Token, but you can use any OAuth 2.0 Authorization Code flow you prefer.

In Postman:

  1. Open a new request → Authorization tab.

  2. Type = OAuth 2.0

  3. Click Get New Access Token.

  4. Make sure the fields are:

Field

Value

Auth URL

https://login.salesforce.com/services/oauth2/authorize

Access Token URL

https://login.salesforce.com/services/oauth2/token

Client ID

Your Salesforce Client ID/Consumer Key generated in Step 2

Client Secret

Your Salesforce Client Secret generated in Step 2

Scope

api refresh_token

Grant Type

Authorization Code

Callback URL

https://oauth.pstmn.io/v1/callback

Client Authentication

“Send as Basic Auth header” or “Send client credentials in body” (either works)

  1. Click Get New Access Token, log in to Salesforce, and click Allow.

After successful authorization, you’ll see a token response like this in Postman - the refresh_token field is what you need.:

CODE
{
  "access_token": "00Dxx0000000001!AQkAQ...",
  "refresh_token": "5Aep861FJ0Txxxxxx",
  "instance_url": "https://yourInstance.my.salesforce.com",
  "id": "https://login.salesforce.com/id/00Dxx0000000001/005xx0000012345",
  "token_type": "Bearer",
  "issued_at": "1731000000000",
  "signature": "D3Kp...",
  "scope": "api refresh_token"
}

Step 4: Create a Datasource in PocketQuery

Open PocketQuery Administration → Datasources, and create a new REST datasource:

Field

Value

Name

Salesforce

Type

REST OAuth2

Base URL

https://<YOUR-URL>.develop.my.salesforce.com

Replace <YOUR-URL> with the URL you see in your browser, when creating/editing your External Client App.

Authentication URL

https://login.salesforce.com/services/oauth2/token

Client ID

Your Salesforce Client ID/Consumer Key generated in Step 2

Client Secret

Your Salesforce Client Secret generated in Step 2

Refresh Token

Your Refresh Token generated in Step 3

You can now test your connection by clicking the Test connection link at the bottom. If everything works as expected, click Create Datasource.

Step 5: Create a Converter in PocketQuery

Go to PocketQuery Administration → Converter, and create a new Converter. This will display your contacts in a neat table:

CODE
function convert(json) {
  const data = JSON.parse(json);

  return data.records.map(contact => ({
    'E-Mail': contact.Email || '',
    'First name': contact.FirstName || '',
    'Last name': contact.LastName || ''
  }));
}

Step 6: Create a Query in PocketQuery

Go to PocketQuery Administration → Queries, and create a new Query that fetches your contacts.

Field

Value

Name

Salesforce Contacts

Datasource

Salesforce

Converter

Name of the Converter created in Step 5

REST URL

/services/data/v60.0/query?q=SELECT+Id,FirstName,LastName,Email+FROM+Contact

That’s it! After clicking Save Query, you can test your query in the Query Preview and use it on any Confluence Page with the PocketQuery Macro:

Table with Contacts from Salesforce displayed in Confluence

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.