BucketService::getBuckets() does not return all buckets for an organization (influxdb-client-php)

Hello everyone,

I need to develop a web interface that queries our organizations/buckets in InfluxDB to provide first level information to our users. I’m developing this information in PHP 8.2 using the influxdb-client-php client.

First, I want to list my organizations and buckets in selectBoxes to create filters. No problem getting my organization list, but I can’t list the buckets. All I get in response are “system” buckets (_monitoring and _tasks).

Let’s take an example. I have an organization named ‘test’ (I know, it’s very original) which contains the buckets ‘bourges_ovins’, bourges_‘caprins’ and ‘test’ (yes, again).

I use the following code:

    #[Route('/buckets', name: 'app_bucket_index')]
    function index(Request $request) : Response 
    {           
        $data["controller_name"] = "BucketController";
        $data["projectName"]     = $_ENV["PROJECT_NAME"];

        $options            = InfluxClient::readInfluxDBOptionsFromProperties();
        $client             = InfluxClient::getInfluxDBClient($options);
        $bucketService      = $client->createService(BucketsService::class);
        $buckets            = $bucketService->getBuckets(null, null, null, null, "test", null, null, null);
        $data["buckets"]    = $buckets == null ? array(): $buckets["buckets"];

        return $this->render('bucket/index.html.twig', $data);
    }

I should get 5 buckets: _monitoring, _tasks, bourges_caprins, bourges_ovins and test as in the ‘influx bucket list’ CLI interface below.

And here’s the result I get:

I don’t understand why I can’t get my ‘user’ buckets.
I’d like to point out in advance that the token I’m using has full --read-XXX rights on all organizations.

Thanks for your help
Thierry

Do you want to change the logic a bit like so:
$buckets = $bucketService->getBuckets();

Try to retrieve all buckets, see if that shows you all of them and then on client side you can filter by organisation name etc.

thank you for your answer @suyash . it’s the first thing I tested

then, as I had 9 times (9 organizations) _tasks and _monitoring buckets, I filtered by organization thinking I’d get my user buckets back … … unfortunately, not !

I see, one thing I can suggest is filing a GitHub issue to request support for this in the sdk. They are generally pretty quick to respond Issues · influxdata/influxdb-client-php · GitHub

For me, changing the token did not solve the issue. In my Go project, I resolved the problem by using a custom query instead of BucketsAPI().

Before:
func (r *Reader) GetBuckets() []string {

if r.client == nil {

    return nil

}

buckets, err := r.client.BucketsAPI().GetBuckets(context.Background())

if err != nil {

    sentry.CaptureException(err)

    log.Fatal(err)

}

result := make(\[\]string, len(\*buckets))

for i, bucket := range \*buckets {

    result\[i\] = bucket.Name

}

return result

}

After:
func (r *Reader) GetBuckets() ([]string, error) {

if r.client == nil {

    return nil, fmt.Errorf("client not initialized")

}



queryAPI := r.client.QueryAPI(r.env.Org)

query := \`buckets()\`



result, err := queryAPI.Query(context.Background(), query)

if err != nil {

    sentry.CaptureException(err)

    return nil, err

}

defer result.Close()



var buckets \[\]string

for result.Next() {

    if name, ok := result.Record().ValueByKey("name").(string); ok {

        buckets = append(buckets, name)

    }

}



if result.Err() != nil {

    sentry.CaptureException(result.Err())

    return nil, result.Err()

}



return buckets, nil

}

The getBuckets() arguments are positional, so "test" may be landing in a different filter than you intend. Check the installed client’s BucketsService::getBuckets() signature in vendor/ and pass the organization’s ID in the orgID parameter (or use named arguments if that version supports them). The API’s org filter is the organization name; it isn’t the same as the bucket name filter.

If your installed signature is getBuckets($name, $orgID, $org, $limit, $after, $offset, $descending), then “test” is being passed as $after, not as the organization filter. Try getBuckets(null, null, “test”) for the org name, or use named arguments if supported: getBuckets(org: “test”). If using orgID, pass the actual organization ID rather than the name.