This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from smartsheet-platform/enterprise-events
Add enterprise events endpoint
- Loading branch information
Showing
10 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Advanced Topics for the Smartsheet SDK for Javascript | ||
|
||
## Event Reporting | ||
The following sample demonstrates best practices for consuming the event stream returned from the Smartsheet Event Reporting feature. | ||
|
||
The sample uses the `smartsheet.events.getEvents` method to request lists of events from the stream. The first request sets the `since` parameter with the point in time (i.e. event occurrence datetime) in the stream from which to start consuming events. The `since` parameter can be set with a datetime value that is either formatted as ISO 8601 (e.g. 2010-01-01T00:00:00Z) or as UNIX epoch (in which case the `numericDates` parameter must also be set to `true`. By default the `numericDates` parameter is set to `false`). | ||
|
||
To consume the next list of events after the initial list of events is returned, set the `streamPosition` parameter with the `nextStreamPosition` attribute obtained from the previous request and don't set the `since` parameter with any values. This is because when using the `get` method, either the `since` parameter or the `streamPosition` parameter should be set, but never both. | ||
|
||
Note that the `moreAvailable` attribute in a response indicates whether more events are immediately available for consumption. If events aren't immediately available, they may still be generating so subsequent requests should keep using the same `streamPosition` value until the next list of events is retrieved. | ||
|
||
Many events have additional information available as a part of the event. That information can be accessed from the data stored in the `additionalDetails` attribute. Information about the additional details provided can be found [here](https://smartsheet-platform.github.io/event-reporting-docs/). | ||
|
||
|
||
```javascript | ||
// Initialize the client | ||
var client = require('smartsheet'); | ||
var smartsheet = client.createClient({ | ||
accessToken: '1234', | ||
logLevel: 'info' | ||
}); | ||
|
||
const currentDate = new Date(); | ||
const dateWeekAgo = currentDate.setDate(currentDate.getDate() - 7); | ||
// The first call to the events reporting API | ||
// requires the since query parameter. | ||
// If you pass in an UNIX epoch date, numericDates must be true | ||
let options = { | ||
queryParameters: { | ||
since: dateWeekAgo, | ||
maxCount: 10, | ||
numericDates: true | ||
} | ||
} | ||
|
||
function getEvents(options) { | ||
smartsheet.events.getEvents(options) | ||
.then((result) => { | ||
printNewSheetEvents(result); | ||
getNextStreamOfEvents(result.moreAvailable, result.nextStreamPosition); | ||
}) | ||
.catch((error) => console.log(JSON.stringify(error))); | ||
} | ||
|
||
function getNextStreamOfEvents(moreEventsAvailable, nextStreamPosition) { | ||
// Subsequent calls require the streamPosition property | ||
options = { | ||
queryParameters: { | ||
streamPosition: nextStreamPosition, | ||
maxCount: 10 | ||
} | ||
} | ||
|
||
if (moreEventsAvailable) { | ||
getEvents(options); | ||
} | ||
} | ||
|
||
// This example is looking specifically for new sheet events | ||
function printNewSheetEvents(result) { | ||
// Find all created sheets | ||
result.data.forEach(function (item) { | ||
if (item.objectType === "SHEET" && item.action === "CREATE") { | ||
console.log(item.additionalDetails.sheetName) | ||
} | ||
}) | ||
} | ||
|
||
getEvents(options); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,11 +219,19 @@ var responsePromise = smartsheet.request.post({ | |
}); | ||
``` | ||
|
||
## Advanced Topics | ||
For details about more advanced features, see [Advanced Topics](ADVANCED.md). | ||
|
||
## Contributing | ||
|
||
If you would like to contribute a change to the SDK, please fork a branch and then submit a pull request. | ||
[More info here.](https://help.github.com/articles/using-pull-requests) | ||
|
||
## Version Numbers | ||
Starting from the v2.77.0 release, Smartsheet SDKs will use a new versioning strategy. Since all users are on the Smartsheet API 2.0, the SDK version numbers will start with 2. The 2nd number will be an internal reference number. The 3rd number is for incremental changes. | ||
|
||
For example, v2.77.0 means that you are using our 2.0 version of the API, the API is synched internally to a tag of 77, and then if there are numbers after the last decimal, that will indicate a minor change. | ||
|
||
## Support | ||
|
||
If you have any questions or issues with this SDK please post on [Stack Overflow using the tag "smartsheet-api"](http://stackoverflow.com/questions/tagged/smartsheet-api) or contact us directly at [email protected]. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var _ = require('underscore'); | ||
|
||
exports.create = function(options) { | ||
var requestor = options.requestor; | ||
|
||
var optionsToSend = { | ||
url: options.apiUrls.events | ||
}; | ||
_.extend(optionsToSend, options.clientOptions); | ||
|
||
var getEvents = (getOptions, callback) => | ||
requestor.get(_.extend({}, optionsToSend, getOptions), callback); | ||
|
||
return { | ||
getEvents : getEvents | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters