Get Predictions
The Einstein Prediction Service provides a REST API endpoint to request a prediction.
Use one of the following to create your request body, Smart Data Discovery Predict Input, Smart Data Discovery Predict Raw Data Input, Smart Data Discovery Predict Record Overrides Input, or Smart Data Discovery Predict Record Input.
In the request body, you specify the prediction definition to use and the rows of data that you want to score. You can specify rows in one of three available formats:
| Format | Description |
|---|---|
Records | Salesforce record Ids associated with the subscribedEntity of the prediction definition (retrieved using a SOQL query). |
RawData | A two-dimensional array of row values in which each row is a comma-separated list of values. |
RecordOverrides | Array of objects containing the Salesforce record Ids. Optionally, override or append values in individual records with an array of row values (in which each row is a comma-separated list of values). |
When you run a prediction, Salesforce applies the model specified in the prediction definition to the set of records and returns a prediction score for each record. If you specify 3 records, for example, you get 3 predictions in the order in which the records were specified in the request.
Sample Request when type is Records
The following example shows a request body in which type is Records. The records attribute provides a comma-separated list of Salesforce record Ids associated with the subscribedEntity of the prediction definition. You can retrieve a list of available prediction definition Ids using the following API request:
You can specify up to 200 Salesforce record Ids. Two records are specified in the following example:
Sample Request when type is RawData
The following example shows a request body in which type is RawData. It names five columns and specifies two records with five data values each. The columns were selected during the story setup process. For more information, see Create a Story.
Sample Request when type is RecordOverrides
The following example shows a request body in which type is RecordOverrides. When specifying row data:
- Each Salesforce record Id represents a record in the
subscribedEntityassociated with the prediction definition. - (Optional) Each row, where specified, contains the values to override or append to the data specified in the associated record.
You can specify up to 200 entries (record entries plus row entries) in a request. For example, if you have 120 record entries, you can override up to 80 record entries with row entries. The following example specifies two columns with two record entries and two overrides.
Sample Request for Predictive Factors and Improvements
Starting in 50.0, this API returns a single prediction value by default. To request prediction factors and improvements, you must ask for them explicitly in the request body. The following code snippet specifies settings to request prediction factors and improvements.
In this example:
maxPrescriptionsspecifies the maximum number of improvements (1-3) to return in the responsemaxMiddleValuesspecifies the number of top predictors (1-3) to return in the responseprescriptionImpactPercentagespecifies the threshold filter (minimum % improvement for the outcome, which in this example is 87%) needed for the improvement to be returned in the response
To learn more about these settings and see these elements on an example Lightning page, see Add Einstein Predictions to a Lightning Page.
The POST response is a Smart Data Discovery Predict List response.
Example POST Response