Connection Creation
The Datagrid API provides an iframe-based embedding solution for connection creation that allows you to integrate third-party service authentication flows directly into your application.Overview
When you need to create connections to third-party services (like Google Drive, Hubspot, Dropbox, etc.), you can embed the Datagrid API connection creation flow in an iframe. The iframe will handle the OAuth flow and authentication, then communicate the results back to your parent application via postMessage events.Basic Implementation
Here’s a React component example that demonstrates how to embed the connection creation iframe:Usage Example
Message Events
The iframe will send various postMessage events to the parent window. All events follow this structure:Available Event Types
datagrid-api/connection-created
Emitted when a new connection is successfully created.
Payload:
datagrid-api/connection-updated
Emitted when an existing connection is successfully updated.
Payload: Same as connection-created event.
datagrid-api/error
Emitted when an error occurs during the connection process.
Payload:
datagrid-api/resize
Emitted when the iframe needs to be resized to accommodate content.
Payload:
datagrid-api/content-loaded
Emitted when the iframe content has finished loading.
Payload: null
Security Considerations
- Always validate the origin of postMessage events to ensure they come from your expected domain
- Implement proper error handling for all message types
- Consider implementing a timeout mechanism for connection creation
- Store connection credentials securely after successful creation
Best Practices
- Event Filtering: Always check that messages are from the expected source and contain the
datagrid-api
prefix - Error Handling: Implement comprehensive error handling for all possible error scenarios
- User Feedback: Provide clear feedback to users about the connection status
- Responsive Design: Handle iframe resizing events to provide a smooth user experience
- Loading States: Show appropriate loading states while the iframe is initializing
Creating a Connection
To get the redirect URL, call thecreateConnection
endpoint with the desired connector ID: