Face API - Person Group PUT 操作期间出现错误 404

Face API - Error 404 during Person Group PUT operation

我尝试通过 js 节点使用人脸 api,但响应始终是 "statusCode": 404,"message": "Resource not found" 有什么我应该错过的正在安装?

这是我的代码

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);
   });

更新

我发现了问题。您只是在请求 url 中丢失了 /,并且需要在 uriBase 之后添加 params.personGroupId

错误图片:

正确图片:

列出personGroup,找到刚刚创建的202006090101

原始

代码:

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);
});

图片:

详情:

  1. 创建项目文件夹,用vscode
  2. 打开
  3. 在文件夹中创建一个test.js文件,粘贴我的测试代码并替换uriBasepersonGroupIdOcp-Apim-Subscription-Key.
  4. 运行npm i,成功后运行npm install request
  5. 运行 node test.js