• vybs88
  • 5 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
  • 1


I'm trying to set up a Lightning app that will allow a user to provide a url to a zip file, have that zip file loaded as a dataset into the predictive vision service, then specify the newly created dataset to be trained into a datamodel. I'm able to load the data model from the menu, and get back a dataset id.

But I'm stuck on how to call the training service. I modified the provided VisionController code as follows:

    public static String postDatasetTrain(string datasetId, string datasetName) {
        // Get a new token
        JWT jwt = new JWT('RS256');
        jwt.cert = 'SelfSignedCert_18Jul2016_235259';
        jwt.iss = 'developer.force.com';
        jwt.sub = 'joseph.daily@careerbuilder.com';
        jwt.aud = 'https://api.metamind.io/v1/oauth2/token';
        jwt.exp = '3600';
        String access_token = JWTBearerFlow.getAccessToken('https://api.metamind.io/v1/oauth2/token', jwt);      
        String VISION_API = 'https://api.metamind.io/v1/vision';
        String DATA_TRAIN = VISION_API + '/train';
        string contentType = HttpFormBuilder.GetContentType();
        //  Compose the form
        string form64 = '';      
        form64 += HttpFormBuilder.WriteBoundary();
        form64 += HttpFormBuilder.WriteBodyParameter('name', datasetName);
        form64 += HttpFormBuilder.WriteBoundary();
        form64 += HttpFormBuilder.WriteBodyParameter('datasetId', datasetId);        
        form64 += HttpFormBuilder.WriteBoundary(HttpFormBuilder.EndingType.CrLf);
        blob formBlob = EncodingUtil.base64Decode(form64);
        string contentLength = string.valueOf(formBlob.size());
        //  Compose the http request
        HttpRequest httpRequest = new HttpRequest();
        httpRequest.setHeader('Connection', 'keep-alive');
        httpRequest.setHeader('Content-Length', contentLength);
        httpRequest.setHeader('Content-Type', contentType);
        httpRequest.setHeader('Authorization','Bearer ' + access_token);
        Http http = new Http();
        HTTPResponse res = http.send(httpRequest);
        system.debug('res: ' + res);
        system.debug('res.getBody(): ' + res.getBody());
        return res.getBody();


But the response that comes back is always a 403 : forbidden message.

Is there anything obvious causing this in my code?

Having trouble with the sign-up process for the new Predictive Vision Service?  Please let us know here and we will work to help you through the process.