Einstein Discovery Prediction Service on Postman — 3 Easy Steps

Bharadwaj Tanikella
6 min readMar 12, 2020
Using Einstein Discovery Predict on Postman API tool

While I’m getting used to the #remoteworking lifestyle by sorting out and setting up tools to be more productive in my work. I thought I would share one of the tools I use every day for development and testing.

What are Einstein Discovery and Postman?
Einstein Discovery is an Augmented Analytics tool that enables business users to automatically discover valuable patterns in their data. Everything in Einstein Discovery is accomplished through simple clicks, rather than building complex AI models from scratch. Postman, on the other hand, is an API collaboration tool that allows users to easily work with public APIs.

Einstein Discovery is a comprehensive CRM Analytics product, which offers various features, such as Einstein Data Insights on Salesforce Reports, Stories in Einstein Analytics, Predictions on Salesforce Records, and Automated Scoring on Records. Einstein Prediction Service is Einstein Discovery’s collection of public APIs that allows users to get predictions on their data by making an API call from any external environment or platform. Through Einstein Prediction Service, the power of Einstein Discovery can be exported anywhere. And we know answering the “What will happen” questions in a business setting can be quite powerful. Because it provides publicly available APIs, we are not limited to working within just the Salesforce Ecosystem.

Prerequisites:

How can I use Einstein Prediction Service APIs on Postman?

Three Easy Steps:

  1. Set up a Connected Application.
  2. Set up Postman with Connected App Credentials.
  3. Use Einstein Discovery APIs.

I. Connected Application Setup

This allows Postman to connect to your Salesforce Org securely.

Trailhead: Connected App Basics

Click on the Setup icon on the Top Right of the Page

From your home screen, please make your way to the Setup page.

In the Search Bar, type App to Filter for the App Manager

From the Setup Page, use the toolbar on the left to navigate to the App Manager page

Click the New Connected App Button

In the App Manager page, click the New Connected App button

Enter the relevant information for the Connected App
  • Set Connected App Name: Add a Name that is descriptive and easily distinguishable
  • Set API Name: Follow the Salesforce API Name structure
  • Set Contact Email: Email
  • Click Enable OAuth Settings: Enabled
  • Set Callback URL: I have used https://login.salesforce.com, Use the URL associated with your Salesforce org (for example, https://test.salesforce.com/)
  • Set Selected OAuthScopes: Access and manage your data (api) & Access and manage your wave data (wave_api)

After completing the form, go ahead and create the Connected Application.

The result of the Connected Application

A Connected Application is created with the Consumer Key and Secret.

You have completed the hardest part of the setup.

II. Set up Postman with Connected App Credentials

This step will set up the Postman tool with the Connected App credentials. You need this to get the Access Token to perform the API calls.

**Optional** Create a New Collection

I created a New Collection to make sure that I have all the Einstein Discovery APIs I work within one place. **Optional**

Create a New Request

Click + New on the left-hand corner of the application and create a New Request

Provide the Name of the Request

I usually create a new Request under the collection I have created and then associate them with each other.

Complete the Request Form.

grant_type : password

client_id : Consumer Key from the created Connected App from Step I

client_secret : Consumer Secret from the created Connected App from Step I

username : Salesforce User Name

password : Salesforce Password

  • Save the Request
  • Click SEND
Once Executed, this is what we see

Once we have executed the above request, the response will be similar to the above example.

Copy access_token Information <IMPORTANT>

Authentication with Salesforce is complete and we are now able to use Salesforce APIs using Postman.

III. Use Einstein Discovery API’s [Prediction Service]

Expected Flow:
Create New Request → Apply Authorization with Access Token → Provide Request Payload → Consume Response

Helpful Documentation for Einstein Discovery APIs:

The following are an example of how to execute GET Prediction Definitions and POST Predict API calls.

[GET] PredictionDefinitions

URL: /services/data/v48.0/smartdatadiscovery/predictionDefinitions

Note: API Version v48.0 will be incremented as Salesforce has new releases.

Create a New Request for Prediction Definitions Call
  • Similar to Step II, we are going to create a New Request for Prediction Definitions.
Prediction Definition API

You should see a Response with Prediction Definitions.

[POST] Predict API

URL: /services/data/v48.0/smartdatadiscovery/predict

New Request For Predict API

Create a new Request for the Predict API call

Authorization Stage of the Request

Every Request for an API call requires us to set up the Authorization.

Because this is a POST call. We need to specify an associated request BODY.
  • Select Body Option
  • Select Body Type: raw
  • Select Body Type Request: JSON
  • Add the JSON Request.

For Example:

{
“predictionDefinition”: “<PredictionDefinitionId>”,
“type”: “Records”,
“records”: [“RecordId1”,”RecordId2”]
}

Congratulations! You have the ED Prediction Service working with Postman. :)

Most common error messages:

Note: This is not a complete list, but something I faced while setting up.

predict’ must be specified Error.

This usually happens when there is a mismatch between the Header Value Content-Type and the request body. We need to make sure the Content-Type: application/json, since we are using a Request Body of a JSON

--

--