1
votes

I am simply strying to call the REST API end point of a machine learning experiment created with Azure. I keep getting this error message:

{
    "error": {
        "code": "BadArgument",
        "message": "Invalid argument provided.",
        "details": [
            {
                "code": "RequestBodyInvalid",
                "message": "No request body provided or error in deserializing the request body."
            }
        ]
    }
}

I have looked it up on their documentation: https://docs.microsoft.com/en-us/azure/machine-learning/machine-learning-web-service-error-codes

All it says is that my bod is empty, I am not sure how can it be empty, here is my code:

router.post('/rating/new', function(req, res) {
    var postData = {
        "Inputs": {
            "input2":
                [
                    {
                        'Col1': "A11",
                        'Col2': "6",
                        'Col3': "A34",
                        'Col4': "A43",
                        'Col5': "1169",
                        'Col6': "A65",
                        'Col7': "A75",
                        'Col8': "4",
                        'Col9': "A93",
                        'Col10': "A101",
                        'Col11': "4",
                        'Col12': "A121",
                        'Col13': "67",
                        'Col14': "A143",
                        'Col15': "A152",
                        'Col16': "2",
                        'Col17': "A173",
                        'Col18': "1",
                        'Col19': "A192",
                        'Col20': "A201",
                        'Col21': "1",
                    }
                ],
        },
        "GlobalParameters":  {
        }
    };

    // Configure the request
    var options = {
        url: config.ML_PREDICTIVE.url,
        method: 'POST',
        headers: {
            'Content-Type':'application/json',
            'Authorization':('Bearer ' + config.ML_PREDICTIVE.apiKey)},
        form: postData
    }

    console.log(JSON.stringify(options));

    // Start the request
    request.post(options, function (error, response, body) {
        if(error){
            res.status(403).send(error);
        }
        if(response.statusCode != 200){
            res.status(403).send(response.body);
        }
        if (!error && response.statusCode == 200) {
            console.log(body)
        }
    })
});

The only thing I see that could go wrong is that "form" in the request is not considered body by azure, I have tried with "body" as well no success.

Please help !

1

1 Answers

0
votes

According to the code you provided, the variable postData is not valid JSON string. You'd need to use JSON.stringify() method to convert postData value to a JSON string before you send a POST request.