I'm using Spring Boot and a Service Account to send Google Chat notifications. In my application, each user provides their own target spaceId in their profile. The app retrieves this ID and sends a message to that user-configured space.
This works for some users, but fails for others with a 403 Forbidden error.
{
"error": {
"code": 403,
"message": "Permission denied to perform the requested action on the specified resource, or the resource doesn't exist.",
"status": "PERMISSION_DENIED"
}
}
Simplified Code: My code builds a standard RestTemplate call to the Google Chat API endpoint. The userConfiguredSpaceId is dynamic based on the user profile.
@Service
public class GoogleChatService {
public void sendMessage(String message, String userConfiguredSpaceId) {
String accessToken = getServiceAccountAccessToken();
String url = "https://chat.googleapis.com/v1/spaces/" + userConfiguredSpaceId + "/messages";
HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth(accessToken);
// ... build HttpEntity
// This line throws the 403 Forbidden
restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
}
}
Key Debugging Finding:
- My Service Account authenticates successfully.
- Crucially, if a failing user changes the spaceId in their profile to a known-good spaceId (one that works for me), the notification succeeds.
This proves my application's code and authentication logic are correct, and the issue is tied to the specific spaceId the user has provided.
My Question:
Is it correct to conclude that this 403 error is caused by one of these two configuration issues?
The spaceId stored in the failing user's profile is invalid (e.g., a typo or from a deleted space).
The spaceId is valid, but my Service Account (client_email) has not been added as a member to that specific chat space.
Are there any other possible causes I'm overlooking?
-
1"Is it correct to conclude..." those (mire the second one) seem like likely issues, but you can confirm this by addressing them and seeing if your problem continuessmallpepperz– smallpepperz2025年11月04日 13:17:47 +00:00Commented Nov 4, 2025 at 13:17