Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 98c1ce8

Browse files
authored
Merge pull request #76 from smartsheet-platform/enterprise-events
Add enterprise events endpoint
2 parents 150596b + 1c879c5 commit 98c1ce8

File tree

10 files changed

+120
-4
lines changed

10 files changed

+120
-4
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
language: node_js
22

33
node_js:
4-
- "lts/boron"
5-
- "lts/argon"
4+
- "lts/carbon"
65

76
before_install:
87
- git clone https://github.com/smartsheet-platform/smartsheet-sdk-tests.git

ADVANCED.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Advanced Topics for the Smartsheet SDK for Javascript
2+
3+
## Event Reporting
4+
The following sample demonstrates best practices for consuming the event stream returned from the Smartsheet Event Reporting feature.
5+
6+
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`).
7+
8+
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.
9+
10+
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.
11+
12+
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/).
13+
14+
15+
```javascript
16+
// Initialize the client
17+
var client = require('smartsheet');
18+
var smartsheet = client.createClient({
19+
accessToken: '1234',
20+
logLevel: 'info'
21+
});
22+
23+
const currentDate = new Date();
24+
const dateWeekAgo = currentDate.setDate(currentDate.getDate() - 7);
25+
// The first call to the events reporting API
26+
// requires the since query parameter.
27+
// If you pass in an UNIX epoch date, numericDates must be true
28+
let options = {
29+
queryParameters: {
30+
since: dateWeekAgo,
31+
maxCount: 10,
32+
numericDates: true
33+
}
34+
}
35+
36+
function getEvents(options) {
37+
smartsheet.events.getEvents(options)
38+
.then((result) => {
39+
printNewSheetEvents(result);
40+
getNextStreamOfEvents(result.moreAvailable, result.nextStreamPosition);
41+
})
42+
.catch((error) => console.log(JSON.stringify(error)));
43+
}
44+
45+
function getNextStreamOfEvents(moreEventsAvailable, nextStreamPosition) {
46+
// Subsequent calls require the streamPosition property
47+
options = {
48+
queryParameters: {
49+
streamPosition: nextStreamPosition,
50+
maxCount: 10
51+
}
52+
}
53+
54+
if (moreEventsAvailable) {
55+
getEvents(options);
56+
}
57+
}
58+
59+
// This example is looking specifically for new sheet events
60+
function printNewSheetEvents(result) {
61+
// Find all created sheets
62+
result.data.forEach(function (item) {
63+
if (item.objectType === "SHEET" && item.action === "CREATE") {
64+
console.log(item.additionalDetails.sheetName)
65+
}
66+
})
67+
}
68+
69+
getEvents(options);
70+
```

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Unreleased
99

10+
## 2.77.0 - May 9, 2019
11+
- Added events endpoint to retrieve events that are occurring in your Smartsheet plan.
12+
1013
## 1.5.0 - February 18, 2019
1114
- Updated documentation regarding the usage of baseUrl to clarify how clients can access smartsheetgov
1215
- Added constant for smartsheetgov

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,19 @@ var responsePromise = smartsheet.request.post({
219219
});
220220
```
221221

222+
## Advanced Topics
223+
For details about more advanced features, see [Advanced Topics](ADVANCED.md).
224+
222225
## Contributing
223226

224227
If you would like to contribute a change to the SDK, please fork a branch and then submit a pull request.
225228
[More info here.](https://help.github.com/articles/using-pull-requests)
226229

230+
## Version Numbers
231+
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.
232+
233+
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.
234+
227235
## Support
228236

229237
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].

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ exports.createClient = function(clientOptions) {
8787
return {
8888
constants : require('./lib/utils/constants.js'),
8989
contacts : require('./lib/contacts/').create(options),
90+
events : require('./lib/events/').create(options),
9091
favorites : require('./lib/favorites/').create(options),
9192
folders : require('./lib/folders/').create(options),
9293
groups : require('./lib/groups/').create(options),
@@ -108,5 +109,5 @@ exports.createClient = function(clientOptions) {
108109

109110
exports.smartSheetURIs = {
110111
defaultBaseURI: 'https://api.smartsheet.com/2.0/',
111-
govBaseURI: 'https://api.smartsheetgov.com/2.0'
112+
govBaseURI: 'https://api.smartsheetgov.com/2.0/'
112113
}

lib/events/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var _ = require('underscore');
2+
3+
exports.create = function(options) {
4+
var requestor = options.requestor;
5+
6+
var optionsToSend = {
7+
url: options.apiUrls.events
8+
};
9+
_.extend(optionsToSend, options.clientOptions);
10+
11+
var getEvents = (getOptions, callback) =>
12+
requestor.get(_.extend({}, optionsToSend, getOptions), callback);
13+
14+
return {
15+
getEvents : getEvents
16+
};
17+
};

lib/utils/apis.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
contacts : 'contacts/',
3+
events : 'events/',
34
favorites : 'favorites/',
45
folders : 'folders/',
56
groups : 'groups/',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "smartsheet",
3-
"version": "1.5.0",
3+
"version": "2.77.0",
44
"description": "Smartsheet JavaScript client SDK",
55
"main": "index.js",
66
"scripts": {

test/functional/client_test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ describe('Client Unit Tests', function() {
3939
});
4040
});
4141

42+
describe('#Events', function() {
43+
it('should have Events object', function() {
44+
smartsheet.should.have.property('events');
45+
Object.keys(smartsheet.events).should.be.length(1);
46+
});
47+
48+
it('should have Events GET methods', function() {
49+
smartsheet.events.should.have.property('getEvents');
50+
});
51+
});
52+
4253
describe('#Favorites', function() {
4354
it('should have Favorites object',function(){
4455
smartsheet.should.have.property('favorites');

test/functional/endpoints_test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ describe('Method Unit Tests', function () {
1515
{ name: 'listContacts', stub: 'get', options: undefined, expectedRequest: {url: "contacts/" }},
1616
]
1717
},
18+
{
19+
name: 'events',
20+
methods: [
21+
{ name: 'getEvents', stub: 'get', options: {}, expectedRequest: {url: "events/" }}
22+
]
23+
},
1824
{
1925
name: 'favorites',
2026
methods: [

0 commit comments

Comments
 (0)