Google Docs Update Action
Learn how to create an execution action that allows Glean Assistant to update Google Documents programmatically
Overview
This guide demonstrates how to create an execution action that enables Glean Assistant to update Google Documents. You’ll learn how to configure the OpenAPI specification, set up OAuth authentication, and deploy the action for use within your organization.
Before proceeding, ensure you have:
- Admin or app developer access to Glean
- Access to Google Cloud Console
- Familiarity with OAuth 2.0 authentication flows
Implementation Steps
Preparing the OpenAPI Specification
The first step involves creating a properly formatted OpenAPI specification that defines how Glean Assistant will interact with the Google Docs API. We’ll use the following endpoint:
While Google doesn’t typically provide OpenAPI specs publicly, you can construct one using their documentation or reference third-party sources.
Here’s the complete OpenAPI specification:
Creating the Action
Navigate to Admin console > Platform > Actions and create a new action from scratch.
Basic Information Configuration
Configure the following settings:
- Display name: Choose a descriptive name (e.g., “Google Docs Updater”)
- Description: Explain the action’s functionality
- Unique identifier: Set a unique ID (e.g., “googleDocsUpdate”)
- Action type: Select “Action” since this will modify documents
Trigger Condition Setup
In the trigger condition, provide comprehensive guidance for when Glean Assistant should use this action. Include:
- Specific use cases that should trigger the action
- Examples of appropriate user queries
- Cases where the action should not be used
Functionality Configuration
Paste the OpenAPI specification you prepared in Step 1. Since we’re using Google’s API directly, leave the “Use existing on-premise server” option unchecked.
Setting Up Authorization
The action requires OAuth 2.0 authentication to interact with Google Docs securely.
Google Cloud Console Configuration
- Visit the Google Cloud Console Credentials page
- Create new OAuth 2.0 credentials:
- Select “Web Application” as the application type:
Redirect URI Configuration
Add the following redirect URI to your OAuth client configuration:
The unique identifier in the redirect URI must match exactly with the identifier you set when creating the action, including case sensitivity.
OAuth Settings in Glean
Configure these OAuth settings in the Authentication section:
Enable Google Docs API
- Navigate to the Google Cloud Console
- Enable the Google Docs API for your project:
Testing and Deployment
After configuration, thoroughly test the action before deployment.
Testing Process
- Click the testing URL provided after saving the action
- Issue test queries to verify proper triggering
- Use the “Review and confirm” interface:
- Verify document changes:
Before changes:
After changes:
Deployment Configuration
Deploy the action through the deploy tab:
You can:
- Enable the action for all teammates
- Restrict access to specific teammates
- Configure deployment settings for Chat or AI Apps integration
Implementation Guidelines
OpenAPI Specification Best Practices
When preparing your OpenAPI specification for Google Docs integration:
Field Descriptions
The quality of field descriptions significantly impacts Glean Assistant’s ability to populate them correctly. Consider these guidelines:
- Make descriptions actionable and specific
- Include examples of valid values
- Explain the business context of each field
- Clarify relationships between fields
Schema Structure
Your schema structure affects how Glean Assistant interprets the API:
- Keep the schema as flat as possible
- Use meaningful field names that reflect their purpose
- Leverage built-in formats (like
date-time
) where applicable - Include proper type constraints and validations
Google Docs API Considerations
When working with the Google Docs API:
Document Operations
Choose the right operation type for your use case:
- Use
insertText
for adding new content without affecting existing text - Use
replaceAllText
when you need to modify existing content - Consider using
index: 1
for insertions to maintain consistent behavior - Handle formatting through plain text markers (like asterisks for bullets)
Error Handling
Common issues to watch for:
- Document permissions mismatches
- Rate limiting constraints
- Invalid document IDs
- Concurrent modification conflicts
Authentication Setup Tips
OAuth Configuration
Important considerations for OAuth setup:
- Always use
access_type=offline
to enable refresh tokens - Include appropriate error handling for token expiration
- Consider implementing token rotation for security
- Monitor token usage and implement proper logging
Integration Best Practices
User Experience
Optimize the action for user interaction:
- Provide clear feedback when the action is processing
- Include meaningful error messages
- Allow users to preview changes before applying them
- Maintain consistent behavior across different document types
Performance Optimization
Ensure efficient operation:
- Batch related operations when possible
- Implement appropriate timeouts
- Cache frequently used document metadata
- Monitor action execution times
Common Pitfalls to Avoid
Watch out for these common implementation mistakes:
-
Document ID Handling
- Not properly extracting IDs from URLs
- Failing to validate ID format
- Not handling shared drive documents correctly
-
Permission Issues
- Insufficient OAuth scopes
- Missing document-level permissions
- Incorrect service account configuration
-
Content Formatting
- Ignoring existing document structure
- Not handling special characters properly
- Incorrect handling of line breaks and paragraphs
Testing Recommendations
Comprehensive Testing
Implement thorough testing across these scenarios:
- Different document types and sizes
- Various content modification patterns
- Edge cases in text replacement
- Multiple user permission levels
- Concurrent access situations
Maintenance and Monitoring
Ongoing Operations
Establish these operational practices:
- Regular OAuth credential rotation
- Usage pattern monitoring
- Error rate tracking
- User feedback collection
- Performance metric monitoring
Troubleshooting
If you encounter issues during setup or execution:
- Verify OAuth credentials are correctly configured
- Ensure the Google Docs API is enabled
- Check that the redirect URI exactly matches your action’s configuration
- Verify the user has appropriate permissions in both Glean and Google Docs
Next Steps
After successful implementation, consider:
- Creating documentation for end users
- Setting up monitoring for action usage
- Establishing a process for maintaining OAuth credentials
- Planning for periodic reviews of API specifications as the Google Docs API evolves
Was this page helpful?