首页 > 解决方案 > “RESTAPI-INVALIDREQ:(错误:FOER0000)无效请求:原因:uri urlList.json 的无效补丁:无效路径:/test/

问题描述

我有一个名为 urlList.json 的带有以下 JSON 文档的 marklogic 数据库

{
   "test": {
             "ip": "10.10.10.10", 
             "fqdn": "www.test.test"
            }
}

我正在尝试使用补丁添加到带有 marklogic rest API 的测试对象。我正在使用带有 request-promise 模块的 Node 这是代码

var options = {
  method: 'PATCH',
  url: 'https://test:8000/v1/documents',
  qs: { database: databaseName, uri: 'urlList.json' },
  headers:
    {
      'Content-Type': 'application/json',
      Accept: 'application/json'
    },
  strictSSL: false,
  auth: {
    user: userName,
    pass: password,
    sendImmediately: false
  },
  body: JSON.stringify({
    "patch": [
      {
        "insert": {
          "context": "/test/",
          "position": "last-child",
          "content": { "test": "test"}
        }
      }
    ]
  })
};

request(options)
  .then(results => {
    return resolve(results);
  })
  .catch(err => {
    return reject(err);
  })

运行时的期望结果是

{
   "test": {
             "ip": "10.10.10.10", 
             "fqdn": "www.test.test",
             "test": "test"
            }
}

每次运行时都会出现以下错误

"400 - "{\"errorResponse\":{\"statusCode\":400, \"status\":\"Bad 
Request\", \"messageCode\":\"RESTAPI-INVALIDREQ\", 
\"message\":\"RESTAPI-INVALIDREQ: (err:FOER0000) Invalid request:  
reason: invalid patch for uri urlList.json: invalid path: /test/\"}}""

这是发送的正文

"{"patch":[{"insert":{"context":"/test/","position":"last- 
child","content":{"test":"test"}}}]}"

标签: node.jsrestmarklogic

解决方案


路径必须选择一个节点。因此,路径不能以分隔符结尾。这就是信息试图传达的内容。

它适用于路径/test吗?

顺便说一句,MarkLogic 提供了一个支持 Promise 的 Node.js API。这可能更容易使用。

希望有帮助,


推荐阅读