Why does the InfluxDBClient.getBucketsApi().findBuckets() API method always return an empty list of buckets?

Hello

I have an InfluxDB 2.7 OSS server on which I store feed distribution data for several geographical sites (organization) with several farms (bucket).

One of my use cases is to provide all the consumption data for a geographical site, which requires a Flux query across several buckets.

As I haven’t found a method for this type of query, I use the InfluxDBClient.getBucketsApi().findBuckets() method to retrieve the list of buckets, query them one by one and then aggregate the results.

However, on the same InfluxDB connection, with a valid token of type all-access, I manage to retrieve a bucket from the findBucketByName method, but the findBuckets method systematically returns an empty list of buckets.

The equivalent curl query works :

curl 'https://my.server.url:8086/api/v2/buckets?org=test' \
     --header "Authorization: Token myAllAccessToken" \
     --header "Accept: application/json" \
     --header "Content-Type: application/json"

What could be the reason for this malfunction? Below is the code for my test method. If I’m not completely clear, don’t hesitate to ask me questions.

Thanks for your reply

Thierry

public static List<Bucket> getBuckets(String url, String org, String token)
{
    InfluxDBClientOptions options = InfluxDBClientOptions.builder()
                                                         .url( url )
                                                         .org( org )
                                                         .authenticateToken( token.toCharArray() )
                                                         .build();      

    try (InfluxDBClient influxClient = InfluxDBClientFactory.create(options))
    {
        List<Bucket> buckets = influxClient.getBucketsApi().findBuckets();
        
                    // --- only for tests ---
                    for(Bucket b:buckets)
                        System.out.println(b.getName());
        
                    Bucket tasks        = influxClient.getBucketsApi().findBucketByName("_tasks");
                    Bucket monitoring   = influxClient.getBucketsApi().findBucketByName("_monitoring");
                    Bucket test         = influxClient.getBucketsApi().findBucketByName("test");
        
                    System.out.println(tasks.getName());
                    System.out.println(monitoring.getName());
                    System.out.println(test.getName());
                    // --------------------
        
        return buckets;
    }
}

Hello @theirman,
Thanks for your question. That’s a really interesting use case. Can you tell me more about it? I love learning about agritech.

Hmm I’m not sure. Does the cURL always return a list? Can you use a library to execute cURL instead with c#? Please bear with me I’m not super familiar with c#.
Can you try the findBucketsAsync method instead?

Hello @Anaisdg

Thank you for your reply. I should mention, as I forgot in my post, that I’m working in Java here.

Yes, the curl method systematically returns a response containing my buckets.
But this morning I just found an alternative solution that gives me the exact result I expected. I must have been tired last week not to have seen it:

List<Bucket> buckets = influxClient.getBucketsApi().findBucketsByOrgName("test");

As for context, I’m currently working on piloting patented feed dispensers that will eventually enable us to distribute the exact amount of food each of our animals needs, thus optimizing the animal’s needs and minimizing food waste.

Have a nice day and thanks again for your help.
Thierry

Hello @theirman,
Thanks for sharing! of course that’s what we’re here for.
That’s a super cool use case. Would you be willing or interested in writing a quick blog about your use case? I think our community would love to learn more about it.