Skip to content

Instantly share code, notes, and snippets.

@mathurs
Created July 25, 2020 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathurs/991a5507f533aa9e36f7608f7316d056 to your computer and use it in GitHub Desktop.
Save mathurs/991a5507f533aa9e36f7608f7316d056 to your computer and use it in GitHub Desktop.
Example script to export Data from Browsee
/*!
* Browsee Data Export Script (https://browsee.io/)
* Copyright 2019-2029 Heroteck Solutions Pvt. Ltd.
* Licensed under Apache 2.0 License (https://www.apache.org/licenses/LICENSE-2.0)
*
* Example script to export data from Browsee.
*/
const request = require("request");
var getOptions = function(from) {
return {
method: 'POST',
url: 'https://api.browsee.io/api/v1/export/sessions',
headers: {
'cache-control': 'no-cache',
'content-type': 'application/json'
},
body: {
apiKey: '<Your Project API Key Here>',
secretKey: '<Your Project Secret Key Here>',
select: [ 'duration', 'tags', 'urls', 'userId' ],
from: from,
},
json: true
};
}
// Fetch data
var getData = function(from, callback) {
var options = getOptions(from);
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(JSON.stringify(body));
callback(body);
});
}
// Recursively process payload
var processPayload = function(payload) {
if (payload && payload.status == 'success') {
var data = payload.exports.data;
// Process data.
console.log("Received: ", data.length, " sessions.");
// If it requires pagination, make recursive calls
if (payload.exports.to < payload.exports.total) {
getData(payload.exports.to, processPayload);
} else {
// Final processing
console.log("Processed ", payload.exports.total, " sessions.");
}
}
};
// Call to initiate data pull
getData(0, processPayload);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment