googleapis / googleapis/google-api-php-client

Invalid FieldMask error while fetching batched gmail get responses

Open
#2,203 1 comment 1 reaction 0 assignees View on GitHub
type: question
Dominant language
PHP
Stars
9.8k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

I'm trying to make [batched requests](https://developers.google.com/gmail/api/guides/batch) more efficient by getting [partial responses](https://developers.google.com/tasks/performance#partial-response). I'm interested to get just certain headers (from, to, subject) and the message body.

My code works fine when I run it like this:
```php
$client = getClient();
$client->setUseBatch(true);
$service = new Google_Service_Gmail($client);

$batch = new Google_Http_Batch($client, false, null, 'batch/gmail/v1');
$request1 = $service->users_messages->get('me', '17eb57d85dd4933d', ['format'=>'full', 'fields' => 'id,snippet,payload(headers(name,value),body,parts)']);
$request2 = $service->users_messages->get('me', '17eb4fe58a1b3be6', ['format'=>'full', 'fields' => 'id,snippet,payload(headers(name,value),body,parts)']);
$batch->add($request1, "message" . '-17eb57d85dd4933d');
$batch->add($request2, "message" . '-17eb4fe58a1b3be6');
$result = $batch->execute();
var_dump($result);
```

As you can see in the above request, I'm getting ALL the header name, value pairs as `payload(headers(name,value)`. But when I change the code to select only certain headers (I'm interested only in From, To, Subject).
```php
$request1 = $service->users_messages->get('me', '17eb57d85dd4933d', ['format'=>'full', 'fields' => 'id,snippet,payload(headers(name,value)[name=From,To,Subject],body,parts)']);
```

The API throws me an error:
```
Invalid FieldMask 'id,snippet,payload(headers(name,value)[name=From,To,Subject],body,parts)'. Map keys should be represented as ["some_key"].
```

I tried changing it to `headers(name,value)[name="From",name="To",name="Subject"]` and a few other formats but cannot figure out how to get it right. The API documentation too doesn't go in-depth to discuss how to select specific headers in key-value pairs so some help would be appreciated. Thanks.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.