Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

248
Vistas
How to loop request, pulling all data from data feed API using token/version with JavaScript?

I'm using JavaScript to request data from geotab api. I'm looking to figure out how to use a token, or version in geotab, to pull all the data beyond the limit. The issue I'm having is how to loop the feed request to pull all the data.

I tried creating a loop with python logic, thinking I can loop the requests until the current token equals the next token (this should mean it reached the end of the requests). However I found out variables don't work in JavaScript like in python:

while version != nextversion:
   execute data feed request

This is the example code provided by Geotab. The example calls the data feed for Trips data in a date range and limiting it to 10 records each call. It will only return the first and second calls. What would be the best way to loop that feed until I get all the data to the toDate?

const GeotabApi = require('mg-api-js');
const fs = require('fs');

/*Authenticate*/
const authentication = {
    credentials: {
        database: 'database',
        userName: 'username',
        password: 'hunter2'
    },
    path: 'http://server.com/'
}

const api = new GeotabApi(authentication);
api.authenticate( success => {
    console.log('Successful authentication');
}, (error) => {
    console.log('Something went wrong');
});


/* The following JavaScript example shows how to call GetFeed and return a list of Trips. Note that it returns only the first 10 trips and after that another 10. */
var feed = (function(){
             var version = "0000000000000000";
             return {
                 next: function(success){
                     api.call("GetFeed", {
                         "typeName":"Trip",
                             "resultsLimit": 10,
                             "fromVersion": version,
                             "search": {
                             toDate: (new Date()).toISOString(),
                             fromDate: (new Date((new Date()).getTime() - (7 * 24 * 60 * 60 * 1000))).toISOString()
                         }
                     }, function(result){
                         version = result.toVersion;
                         success(result.data);
                     });
                 },
                 reset: function(){
                     version = "0000000000000000";
                 }
             };
             })();
            
             feed.next(function(trips){
                 console.log("First part: ", trips);
                 feed.next(function(trips){
                     console.log("Second part: ", trips);
                 });
             });
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda