盒节点API可以获取文件夹信息,但不能创建文件夹



我确定我在认证周期中做错了什么,但我一直得到500,消息相当模糊。

我从节点服务器调用box。首先,我创建一个客户端:

  const sdk = new BoxSDK({
    clientID: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    appAuth: {
      keyID: process.env.PUBLIC_KEY_ID,
      privateKey: fs.readFileSync(path.resolve(__dirname, process.env.PRIVATE_KEY_PATH)),
      passphrase: process.env.PRIVATE_KEY_PASSPHRASE,
    },
  });

  app.use((req, res, next) => {
    req.sdk = sdk.getAppAuthClient('user', process.env.BOX_USER_ID);
    next();
  });

一旦我创建了客户端,我触发一个请求:

export function yearEnd(req, res) {
  req.sdk.folders.create({
    name: 'test',
    parent: {
      id: '0',
    },
  }, (e, r) => {
    if (e) {
      return res.send(e);
    }
    return res.status(201).send(r);
  });
}

我得到的响应是:

{
    "request": {
        "uri": {
            "protocol": "https:",
            "slashes": true,
            "auth": null,
            "host": "api.box.com",
            "port": 443,
            "hostname": "api.box.com",
            "hash": null,
            "search": null,
            "query": null,
            "pathname": "/2.0/folders",
            "path": "/2.0/folders",
            "href": "https://api.box.com/2.0/folders"
        },
        "method": "POST",
        "headers": {
            "User-Agent": "Box Node.js SDK v1.0.0",
            "Authorization": "[REMOVED BY SDK]",
            "accept": "application/json",
            "content-type": "application/json",
            "content-length": 75
        }
    },
    "response": {
        "statusCode": 500,
        "body": {
            "type": "error",
            "status": 500,
            "code": "internal_server_error",
            "help_url": "http://developers.box.com/docs/#errors",
            "message": "Internal Server Error",
            "request_id": "29462704457e0f3876ee08"
        },
        "headers": {
            "server": "ATS",
            "date": "Tue, 20 Sep 2016 08:29:59 GMT",
            "content-type": "application/json",
            "content-length": "188",
            "cache-control": "no-cache, no-store",
            "strict-transport-security": "max-age=31536000; includeSubDomains",
            "vary": "Accept-Encoding",
            "age": "0",
            "connection": "keep-alive"
        },
        "request": {
            "uri": {
                "protocol": "https:",
                "slashes": true,
                "auth": null,
                "host": "api.box.com",
                "port": 443,
                "hostname": "api.box.com",
                "hash": null,
                "search": null,
                "query": null,
                "pathname": "/2.0/folders",
                "path": "/2.0/folders",
                "href": "https://api.box.com/2.0/folders"
            },
            "method": "POST",
            "headers": {
                "User-Agent": "Box Node.js SDK v1.0.0",
                "Authorization": "[REMOVED BY SDK]",
                "accept": "application/json",
                "content-type": "application/json",
                "content-length": 75
            }
        }
    },
    "statusCode": 500,
    "maxRetriesExceeded": true
}
谁能告诉我我做错了什么?

所以,文档和方法签名不匹配。我不得不进入包里,手工检查代码。要创建,它是:

req.sdk.folders.create(<parent_id>, <folderName>, (e, r) => {...});

最新更新