Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Face API - 400 Request Body is invalid

I am using the Microsoft Face API to build a Facial recognition desktop app using Electron. I can right now detect a face and create a person group, but run into this error when I try and add a person to my person group:

{"error":{"code":"BadArgument","message":"Request body is invalid."}}, 

which is marked as Error 400. Bad request on my console.

This is the API page on how to use this request:

Here is my code, obviously something is wrong with the Data field, but when I use the exact same data in the westCentralUS test server, it is successful. I have tried using and omitting the optional userData field, with a string and an image file.

function createPerson() {

var params = {
        // Request parameters
    };

    $.ajax({
        url: "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/persongroups/students/persons",
        beforeSend: function(xhrObj){
            // Request headers
            xhrObj.setRequestHeader("Content-Type","application/json");
            xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key",apiKey);
        },
        type: "POST",
        // Request body
        data: { name: "John",}
    })
    .done(function(data) {
        alert("success");
    })
    .fail(function() {
        alert("error");
    });
}
like image 483
Rahul Jobanputra Avatar asked Jan 24 '26 14:01

Rahul Jobanputra


1 Answers

Try

data: JSON.stringify({name: "John"})

instead.

like image 66
cthrash Avatar answered Jan 26 '26 05:01

cthrash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!