Problem with axios and GBIF API

Hi. I’m trying to use GBIF API on a node.js project to retrieve occurrence information about some species, but in random cases it returns me a JSON with an exception from java. Am I using it wrong? is it a bug or what? Thank you.

Code:

private async getDataFromGbifAPI(
        offset: number,
        limit: number,
        binomialName: string,
    ) {
        try {
            const {
                data: { results },
            } = await GBIF_OCCURENCE_API.get('/search', {
                params: {
                    scientificName: binomialName,
                    offset,
                    limit,
                },
                timeout: 0,
            });

            const filteredResults = [];

            results.forEach((result: IGbifOccurrence) => {
             ...
            });

            return filteredResults;
        } catch {
            console.log(
                'problem on specie with name:',
                binomialName,
                'at offset',
                offset,
            );

            return [];
        }
    }

It shows on the console:

problem on specie with name: Eichhornia crassipes at offset 6750
problem on specie with name: Eichhornia crassipes at offset 26000

The output which contains the exception:

I’m so sorry this went unanswered @PowerfulCoder25

This would indeed be a bug on our side, but it’s one I think has been fixed as the following snippet runs to completion. We were deploying a change around about the time you posted this (some days before) relating to multivalue fields, which would be the kind of thing that produced that error.

Can you please let me know if the issue remains for you?

var request = require('sync-request')

for (let i = 0; i < 28487; i+=300) {
  let result = request('GET', 'https://api.gbif.org/v1/occurrence/search?scientificName=Eichhornia%20crassipes&limit=300&offset='+i);
  console.log(result.statusCode, i);
};

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.