1

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?

  1. The spaceId stored in the failing user's profile is invalid (e.g., a typo or from a deleted space).

  2. 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?

asked Nov 4, 2025 at 13:05
1
  • 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 continues Commented Nov 4, 2025 at 13:17

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.