Last active
October 1, 2017 18:21
-
-
Save tushar30/1c258f72878b0820512926c39d484df1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HttpRequest req = new HttpRequest(); | |
req.setMethod('POST'); | |
req.setEndpoint('https://api.einstein.ai/v2/vision/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','Car vs Bike 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment