Box node API可以获取文件夹信息,但无法创建文件夹

时间:2016-09-20 08:33:00

标签: box-api

我确信我在auth循环中做错了但是我一直有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
}

有谁能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:0)

因此,文档和方法签名不匹配。我不得不进入包裹并手动检查代码。要创建它,它是:

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