0

我正在尝试使用 Node.js sdk 通过includeget-sheet 请求smartsheet.sheets.getSheet(options)发送参数。API 文档对如何include在 API 调用中添加参数含糊不清。

我在 Smartsheet API 中发现了一篇 Smartsheet 开发人员博客文章Demystifying Query Parameters in the Smartsheet API提供了更多指导,但他们提供的 Node.js 示例代码是无效的 javascript:

// Set options
var options = {
    queryParameters: {
    include: "attachments",
    include: "source",
    includeAll: true
    }
};

// List sheets
smartsheet.sheets.listSheets(options)
    .then(function(response) {

    ... 

在上面的代码中,最后一个include查询参数将覆盖所有先前的值,您将得到一个options丢失“附件”参数的变量:

  queryParameters: {
    include: "source",
    includeAll: true
  }

对我来说,显而易见的解决方案是include采用如下数组:

    include: ["attachments", "source"],

有什么建议么?

4

1 回答 1

0

在使用 SDK 之外,查询字符串所需的任何值include都作为逗号分隔列表添加到 URL。SDK 将采用您为对象include参数提供的值并将其queryParameters添加为include查询字符串的值并将其附加到 URL。与其include在对象中多次提供参数queryParameters或提供数组,不如为您希望使用逗号分隔的所有选项提供单个string值。 例如,请求信息并包含在内的请求如下所示: include
GET Sheetsourceattachments

const options = {
    id:<SHEET_ID>,
    queryParameters : {
        include: 'source,attachments',
        includeAll: true
    }
}

smartsheet.sheets.getSheet(options)
.then(sheet => {
    console.log(sheet);
})
.catch(err => {
    console.log(err);
})

请注意,includeAll查询字符串用于pagination并且可以单独使用以使工作表的所有行都包含在响应中。
此外,如果您在控制台中运行测试请求并logLevel: 'info'在使用访问令牌创建 Smartsheet 客户端时进行设置,您可以看到用于请求的 URL 打印在工作表数据响应上方,它将向您显示 URL 的情况结构化的。

于 2019-09-06T20:57:42.950 回答