Face API - Error 404 during Person Group PUT operation

Viewed 289

I try to use face api by using js node but the response is always "statusCode": 404, "message": "Resource not found" is there something I should miss when installing?

this my code

const uriBase2 = 'https://myendpoint/face/v1.0/persongroups';

const params = {
    'personGroupId': 'dava12345',
};

const options = {
    uri: uriBase2,
    qs: params,
    method: 'PUT',
    body: '{ "name": "group2", "userData": "user-provided data attached to ", "recognitionModel": "recognition_02" }',
    headers: {
        'Content-Type': 'application/json',
        'Ocp-Apim-Subscription-Key' : 'mykey'
    }
};


 request(options, (error, response, body) => {
     if (error) {
       console.log('Error: ', error);
       return;
     }
     let jsonResponse = JSON.stringify(JSON.parse(body), null, '  ');
     console.log('JSON Response\n');
     console.log(jsonResponse);
   });
1 Answers

UPDATE

I find the issue. You just lose / in your request url and need to add params.personGroupId after uriBase.

Error pic:

enter image description here

Correct pic:

enter image description here

List personGroup, find 202006090101 which created just now.

enter image description here

PRIVIOUS

Code:

const request = require('request');

const uriBase = 'https://ea***s.api.cognitive.microsoft.com/face/v1.0/persongroups';

const params = {
    'personGroupId': 'pan***test',
};

const options = {
    url: uriBase,
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'Ocp-Apim-Subscription-Key' : '6e4f6d73***23ddf2f5792'
    }
};

request(options, function(err, res, body) {
    let json = JSON.parse(body);
    console.log(json);
});

Pic:

enter image description here

Details:

  1. Create Project folder, open with vscode
  2. Create a test.js file in folder, paste my test code and replace uriBase,personGroupId and Ocp-Apim-Subscription-Key.
  3. run npm i, when success, then run npm install request
  4. run node test.js
Related