2
votes

I would like to do a lookup in the storage using the JSON API client library and only retrieve the name and generation of each object matching a specific prefix but I am having issues with the fields request parameter.

Executing the following returns the expected objects.

Storage.Objects.List listObjects = null;
listObjects.setVersions(true);
listObjects.setPrefix(myprefix);

URL being created for the request in com.google.api.client.http.HttpRequest is https://www.googleapis.com/storage/v1beta2/b/mybucketname/o?prefix=myprefix&versions=true

However, when I add

listObjects.setFields("name,generation");

with URL created being https://www.googleapis.com/storage/v1beta2/b/mybucketname/o?fields=name,generation&prefix=myprefix&versions=true the below is returned:

{
    "code" : 400,
    "errors" : [ {
        "domain" : "global",
        "location" : "fields",
        "locationType" : "parameter",
        "message" : "Invalid field selection name",
        "reason" : "invalidParameter"
     } ],
     "message" : "Invalid field selection name"
}

How am I supposed to be specifying the fields I want returned? Is the hierarchy of the fields I'm specifying not correct?

Thank you!

Ref: Verified the composition of the URL based on this: https://developers.google.com/storage/docs/json_api/v1/how-tos/performance#partial

1

1 Answers

2
votes

I think what you want is:

fields=items(generation,name)

or with the full URL:

https://www.googleapis.com/storage/v1beta2/b/mybucketname/o?fields=items(generation,name)&prefix=myprefix&versions=true

The APIs Explorer is a great tool for experimenting with request fields like this. It will generate the proper fields for you.