Reputation: 73
"Could you please guide me on how to implement the Smartsheet API client-side code using Browserify? I am trying to use the Smartsheet API in my web application, and I am not sure how to proceed with the client-side implementation. Any help or guidance would be greatly appreciated. Thank you."
I would like to provide some context in this matter. I have an HTML page that enables users to submit their comments/feedback, and upon submission, it updates the Smartsheet sheet. Additionally, it is imperative that I utilize the HTML page for this purpose, and no alternative options are permitted.
These are the steps I have attempted so far.
step 0. Installation of required libraries e.g smartsheet ,browserify
Step 1. Created main.js file with following code.
const client = require('smartsheet');
const smartsheet = client.createClient({
accessToken: 'secret token',
logLevel: 'info'
});
//module.exports = smartsheet;
global.window.smartsheet = smartsheet;
Step 2. Create a bundle
browserify main.js -o bundle.js
Step 3. refer the bundle.js in html page
<script src="./lib/bundle.js"></script>
Step 4. add following function in the script file
function updateSmartsheet(){
// Check if the smartsheet variable is defined
const smartsheet = window.smartsheet;
// Set queryParameters for `include` and pagination
var options = {
queryParameters: {
include: "attachments",
includeAll: true
}
};
// List all sheets
smartsheet.sheets.listSheets(options) //program exits with TypeError: Cannot read property 'write' of undefined
.then(function (result) {
var sheetId = result.data[0].id;
// Load one sheet
smartsheet.sheets.getSheet({id: sheetId})
.then(function(sheetInfo) {
console.log(sheetInfo);
})
.catch(function(error) {
console.log(error);
});
})
.catch(function(error) {
console.log(error);
});
}
getting following error at this line smartsheet.sheets.listSheets(options)
bundle.js:58387 Uncaught (in promise) TypeError: Cannot read property 'write' of undefined
at exports.Console.Console.log (bundle.js:58387)
at transportLog (bundle.js:57729)
at bundle.js:42474
at eachOfArrayLike (bundle.js:40433)
at eachOf (bundle.js:40481)
at Object.eachLimit (bundle.js:42536)
at exports.Logger.Logger.log (bundle.js:57741)
at logRequestBasics (bundle.js:53943)
at Object.logRequest (bundle.js:53910)
at methodRequest (bundle.js:53836)
at Object.get (bundle.js:53793)
at Object.listSheets (bundle.js:52964)
at updateSmartsheet (Dummy.js:160)
I would greatly appreciate any assistance anyone can provide in this matter. I have limited experience with JavaScript.
Upvotes: 1
Views: 197