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.
- Permissions: Einstein Analytics Plus License + Ability to Create a Salesforce Connected App [Manage Connected App Permission]
- Create a Story with the desired Dataset
- Deploy the Story to enable Predictions
How can I use Einstein Prediction Service APIs on Postman?
Three Easy Steps:
- Set up a Connected Application.
- Set up Postman with Connected App Credentials.
- Use Einstein Discovery APIs.
I. Connected Application Setup
This allows Postman to connect to your Salesforce Org securely.
Trailhead: Connected App Basics
From your home screen, please make your way to the Setup page.
From the Setup Page, use the toolbar on the left to navigate to the App Manager page
In the App Manager page, click the New Connected App button
- 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.
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.
I created a New Collection to make sure that I have all the Einstein Discovery APIs I work within one place. **Optional**
Click + New on the left-hand corner of the application and create a New Request
I usually create a new Request under the collection I have created and then associate them with each other.
- Change the Type of Request: from GET to POST
- Provide the URL: https://login.salesforce.com/services/oauth2/token
- Select Body
- Select Body Type as x-www-form-urlencoded
- Enter the following KEYS and VALUES
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 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]
Create New Request → Apply Authorization with Access Token → Provide Request Payload → Consume Response
Helpful Documentation for Einstein Discovery APIs:
Help | Training | Salesforce
salesforce help; salesforce training; salesforce support
The following are an example of how to execute GET Prediction Definitions and POST Predict API calls.
Note: API Version v48.0 will be incremented as Salesforce has new releases.
- Similar to Step II, we are going to create a New Request for Prediction Definitions.
- Set Request Type: GET
- Set URL: <yourSalesforceURL>/services/data/v48.0/smartdatadiscovery/predictionDefinitions
- Click Authorization
- Set Authorization type: OAuth2.0
- Set Access Token: Retrieved from Step II of this article.
- Save the Request
- Send the Request
You should see a Response with Prediction Definitions.
[POST] Predict API
Create a new Request for the Predict API call
Every Request for an API call requires us to set up the Authorization.
- Set Request Type: POST
- Set URL: <yourSalesforceURL>/services/data/v48.0/smartdatadiscovery/predict
- Set Authorization Type: OAuth 2.0
- Set Access Token: Access Token from Step II of this article.
- Select Body Option
- Select Body Type: raw
- Select Body Type Request: JSON
- Add the JSON Request.
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