function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swati TaunkSwati Taunk 

Call AWS ML API request from Apex

I have to integrate AWS Machine Learning service with Salesforce. I implemented JavaScript SDK [http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/MachineLearning.html#predict-property] and it is working well.

But I have to implement API using batch apex and schedule the batch class. [http://docs.aws.amazon.com/machine-learning/latest/APIReference/API_Predict.html]

I managed to implement this using apex but I get incorrect response and also same response for all the records (batch size is 1). Any ideas?
I get different responses for same record. Response received from SDK is correct.

Response from http request-

"{"Prediction":{"details":{"Algorithm":"SGD","PredictiveModelType":"BINARY"},"predictedLabel":"0","predictedScores":{"0":0.03352721035480499}}}"

Response from SDK -

"{"Prediction":{"details":{"Algorithm":"SGD","PredictiveModelType":"BINARY"},"predictedLabel":"1","predictedScores":{"1":0.9637616872787476}}}"
Daniel BallingerDaniel Ballinger
Try capturing the raw HTTP Request from both the browser tools and the Apex Debug log. Then you can compare them to see how the JavaScript initiated API call differs from the Apex call.