Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda