googleapis / googleapis/google-api-php-client-services

GET of Group Settings doesn´t work: response is XML instead of JSON

Open
#6,671 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
1.3k
Forks
320
Avg merge
2h 32m
Merged PRs (30d)
193

Description

The [GET request of the Group Setting API](https://developers.google.com/workspace/admin/groups-settings/v1/reference/groups/get) returns XML, but the google-api-php-client-services expects JSON. It returns an empty [Google\Service\Groupssettings](https://googleapis.github.io/google-api-php-client-services/doctum/Google/Service/Groupssettings/Groups.html) class.

#### Environment details

- PHP version: 8.3.6

Composer packages:
- google/apiclient v2.18.3
- google/apiclient-services v0.397.0

#### Steps to reproduce

1. Use the [GET function of \Google\Service\Groupssettings](https://googleapis.github.io/google-api-php-client-services/doctum/Google/Service/Groupssettings/Resource/Groups.html#method_get)
2. The result will be an empty [\Google\Service\Groupssettings](https://googleapis.github.io/google-api-php-client-services/doctum/Google/Service/Groupssettings/Groups.html) class

#### Workaround
The [PATCH request](https://googleapis.github.io/google-api-php-client-services/doctum/Google/Service/Groupssettings/Resource/Groups.html#method_patch) will return a JSON response and that works without a problem. It is possible to alter 1 deprecated setting via the PATCH request and all the current settings will be returned.

#### JSON decode in the REST class
The [REST class](https://github.com/googleapis/google-api-php-client/blob/main/src/Http/REST.php) is decoding the response and expects JSON:
```php
/**
* Decode an HTTP Response.
* @static
*
* @template T
* @param RequestInterface $response The http response to be decoded.
* @param ResponseInterface $response
* @param class-string|false|null $expectedClass
* @return mixed|T|null
* @throws \Google\Service\Exception
*/
public static function decodeHttpResponse(
ResponseInterface $response,
?RequestInterface $request = null,
$expectedClass = null
) {
$code = $response->getStatusCode();

// retry strategy
if (intVal($code) >= 400) {
// if we errored out, it should be safe to grab the response body
$body = (string)$response->getBody();

// Check if we received errors, and add those to the Exception for convenience
throw new GoogleServiceException($body, $code, null, self::getResponseErrors($body));
}

// Ensure we only pull the entire body into memory if the request is not
// of media type
$body = self::decodeBody($response, $request);

if ($expectedClass = self::determineExpectedClass($expectedClass, $request)) {
$json = json_decode($body, true);

return new $expectedClass($json);
}

return $response;
}
```

#### XML return of the GET request
```xml

tag:googleapis.com,2010:apps:groupssettings:GROUP:example@example.com
Groups Resource Entry
Example

Google

example@example.com
Example
Example
CAN_REQUEST_TO_JOIN
ALL_IN_DOMAIN_CAN_VIEW
ALL_MEMBERS_CAN_VIEW
ALL_MANAGERS_CAN_INVITE
ALL_MANAGERS_CAN_ADD
true
ALL_IN_DOMAIN_CAN_POST
true
en
26214400
true
false
MODERATE_NON_MEMBERS
MODERATE
REPLY_TO_SENDER
false

true

false
false
false
DEFAULT_SELF
DEFAULT_FONT
true
ALL_MEMBERS_CAN_LEAVE
ALL_IN_DOMAIN_CAN_CONTACT
NONE
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
true
ALL_MANAGERS_CAN_APPROVE
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
OWNERS_AND_MANAGERS
false
false
ALL_IN_DOMAIN_CAN_DISCOVER

```

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.