node package manager


itembase-document-stream Build Status

Stream itembase documents. Handles pagination and refreshing the access token if necessary.

npm install itembase-document-stream


As a minimum the constructor requires the resource URL and a valid access token.

var itembase = require('itembase-document-stream');
var JSONStream = require('JSONStream');
itembase('/v1/users/:user_id/transactions', 'access_token')

It's also possible to pass more complex options.

var tokens = {
    access_token: 'access_token',
    refresh_token: 'refresh_token'
var options = {
    client: { id: 'client_id', secret: 'client_secret' },
    urls: { api: '', accounts: '' },
    query: { document_limit: 10 }
var stream = itembase('/v1/users/:user_id/transactions', tokens, options);
stream.on('tokens', function(tokens) {
    // Tokens have been refreshed 
stream.on('data', function(data) {

The client option, together with the refresh_token, is necessary to be able to refresh the access token if it expires. Otherwise an error event is emitted.

It's also possible to override the base URLs in the options map, and pass additional query parameters to the API request.

Additionally a start event is emitted when the first request is performed. It contains, among other things, total number of documents to expect.