Salesforce Einstein Intent categorizes unstructured text into user-defined labels to better understand what users are trying to accomplish. So we can use this API to analyze text from emails, chats, or web forms to:
- Determine which products prospects are interested in, and send customer inquiries to the appropriate sales person.
- Route service cases to the correct agents or departments, or provide self-service options.
- Understand customer posts to provide personalized self-service in your communities.
In my previous post I have already shared about Einstein Vision to predict the image. So today we will cover the basic of Salesforce Einstein Intent, search prediction modal.
Similarly we can use Einstein Intent to make a case prediction and route the case to different user. So that case can be solved much faster speed with less human intervention.

Access Token
The process is same as we have done for Einstein Vision. First if you don’t have API key or access token then you need to create one. So you can follow the same steps as previous post.
Firstly, we will create sample Dataset. In this step, we will provide the data text which we exepct from users. So an intent string example is associated with a label.
You can use sample CSV which I have used or can create your own as well.
Create Dataset
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://api.einstein.ai/v2/language/datasets/upload');
req.setHeader('content-type', 'multipart/form-data; charset="UTF-8"; boundary="1ff13444ed8140c7a32fc4e6451aa76d"');
req.setHeader('Authorization', 'Bearer <TOKEN>');
req.setHeader('Cache-Control', 'no-cache');
// Compose the form
string form64 = '';
form64 += HttpFormBuilder.WriteBoundary();
form64 += HttpFormBuilder.WriteBodyParameter('path', 'https://drive.google.com/uc?export=download&id=1PndbF98dBkHjbJJnS82irelpc_BpFtZl');
form64 += HttpFormBuilder.WriteBoundary();
form64 += HttpFormBuilder.WriteBodyParameter('type', 'text-intent');
form64 += HttpFormBuilder.WriteBoundary(HttpFormBuilder.EndingType.CrLf);
blob formBlob = EncodingUtil.base64Decode(form64);
string contentLength = string.valueOf(formBlob.size());
req.setBodyAsBlob(formBlob);
req.setHeader('Connection', 'keep-alive');
req.setHeader('Content-Length', contentLength);
req.setTimeout(60*1000);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();
system.debug(resp);
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res.getBody());
As this is an Asynchronous request, So we need to make a request to check status.
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://api.einstein.ai/v2/language/datasets/<datasetId>');
req.setHeader('Authorization', 'Bearer <TOKEN>');
req.setTimeout(60*1000);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();
system.debug(resp);
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res.getBody()) ;
Request To train dataset
Secondly we will train that dataset. You can also make request to check status of training. and once training is completed you can make your first prediction.
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://api.einstein.ai/v2/language/train/');
req.setHeader('content-type', 'multipart/form-data; charset="UTF-8"; boundary="1ff13444ed8140c7a32fc4e6451aa76d"');
req.setHeader('Authorization', 'Bearer <TOKEN>');
req.setHeader('Cache-Control', 'no-cache');
// Compose the form
string form64 = '';
form64 += HttpFormBuilder.WriteBoundary();
form64 += HttpFormBuilder.WriteBodyParameter('name', 'Case Routing Model');
form64 += HttpFormBuilder.WriteBoundary();
form64 += HttpFormBuilder.WriteBodyParameter('datasetId', <DATASET ID>);
form64 += HttpFormBuilder.WriteBoundary(HttpFormBuilder.EndingType.CrLf);
blob formBlob = EncodingUtil.base64Decode(form64);
string contentLength = string.valueOf(formBlob.size());
req.setBodyAsBlob(formBlob);
req.setHeader('Connection', 'keep-alive');
req.setHeader('Content-Length', contentLength);
req.setTimeout(60*1000);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();
system.debug(resp);
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res.getBody()) ;
As this is an Asynchronous request, So we need to make a request to check status.
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://api.einstein.ai/v2/language/train/<DATASET ID>');
req.setHeader('Authorization', 'Bearer <TOKEN>');
req.setTimeout(60*1000);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();
system.debug(resp);
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res.getBody());
So our dataset is trained and we are ready to make our first prediction. So below is our sample request.
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://api.einstein.ai/v2/language/intent');
req.setHeader('content-type', 'multipart/form-data; charset="UTF-8"; boundary="1ff13444ed8140c7a32fc4e6451aa76d"');
req.setHeader('Authorization', 'Bearer <TOKEN>');
req.setHeader('Cache-Control', 'no-cache');
// Compose the form
string form64 = '';
form64 += HttpFormBuilder.WriteBoundary();
form64 += HttpFormBuilder.WriteBodyParameter('document', 'Why my shipping address is changed');
form64 += HttpFormBuilder.WriteBoundary();
form64 += HttpFormBuilder.WriteBodyParameter('modelId', '<MODELID>');
form64 += HttpFormBuilder.WriteBoundary(HttpFormBuilder.EndingType.CrLf);
blob formBlob = EncodingUtil.base64Decode(form64);
string contentLength = string.valueOf(formBlob.size());
req.setBodyAsBlob(formBlob);
req.setHeader('Connection', 'keep-alive');
req.setHeader('Content-Length', contentLength);
req.setTimeout(60*1000);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();
system.debug(resp);
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res.getBody());
The text which I used for prediction is “Why my shipping address is changed.” And the response which I got is

So the majority shows label as billing. Which we agree is correct. You can create large dataset to make these prediction even more accurate.
Let me know what you like most about Salesforce Einstein Intent in comments. If you want to add something share with me in comments section.
For more updates like my Facebook page.
Happy Programming 🙂
1 thought on “Salesforce Einstein Intent: A Quick Overview”