I am trying to send include
parameters with a get-sheet request smartsheet.sheets.getSheet(options) using the Node.js sdk. The API documentation is vague on how to add the include
parameters in the API call.
I found a Smartsheet Developers Blog post Demystifying Query Parameters in the Smartsheet API that provides more guidance, but the Node.js example code they provide is invalid javascript:
// Set options
var options = {
queryParameters: {
include: "attachments",
include: "source",
includeAll: true
}
};
// List sheets
smartsheet.sheets.listSheets(options)
.then(function(response) {
...
In the above code the last include
query parameter will override all of the prior values and you will be left with a options
variable that looses the "attachements" parameter:
queryParameters: {
include: "source",
includeAll: true
}
To me the obvious solutions would be for include
to take an array like:
include: ["attachments", "source"],
Any suggestions?
Outside of using the SDK whatever values needed for the include
query string are added to the URL as a comma separated list. The SDK will take the value you provide for the include
parameter of the queryParameters
object and add that as the value for the include
query string and append it to the URL.
Instead of providing the include
parameter multiple times in the queryParameters
object or providing an array you would give a single string
value for include
with all of the options you wish to use comma separated.
For example, a GET Sheet
request that asks for the source
info and attachments
to be included would look like this:
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);
})
Note, the includeAll
query string is for pagination
and can be used separately to have all rows of the sheet included in the response.
Also, if you are running test requests in your console and set logLevel: 'info'
when creating your Smartsheet client with the access token you can see the URL being used for the request get printed out above the sheet data response and it will show you how the URL is being structured.