Skip to main content

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. There are two main flows:
  1. Connection Creation - Authenticate with a third-party service to create a connection
  2. Knowledge from Connection - Use an existing connection to import data as knowledge for your agents

API Flow

Before embedding the iframes, you need to call the appropriate API endpoints to get the redirect URLs.

Step 1: Create a Connection

To create a connection, call the createConnectionRedirectUrl endpoint:

Step 2: Create Knowledge from Connection (Optional)

After a connection is created, you can create knowledge from it. Call the createKnowledgeFromConnection endpoint:

Connection Embed Implementation

The ConnectionEmbed component handles the connection creation flow. It receives the redirect_url from the createConnectionRedirectUrl API call. Here’s a React component example that demonstrates how to embed the connection creation iframe:

Connection Embed Usage Example


Knowledge from Connection Embed

After creating a connection, you can use it to import data as knowledge for your agents. The KnowledgeFromConnectionEmbed component handles this flow.

KnowledgeFromConnectionEmbed Component

This component receives the redirect_url from the createKnowledgeFromConnection API call:

Knowledge from Connection Usage Example

Complete Flow Example

Here’s an example showing the complete flow from connection creation to knowledge import:

Message Events

The iframe will send various postMessage events to the parent window. All events follow this structure:

Available Event Types

Connection Events

datagrid-api/connection-created
Emitted when a new connection is successfully created. Used with the ConnectionEmbed component. Payload:
datagrid-api/connection-updated
Emitted when an existing connection is successfully updated. Payload: Same as connection-created event.

Knowledge Events

datagrid-api/knowledge-created
Emitted when knowledge is successfully created from a connection. Used with the KnowledgeFromConnectionEmbed component. Payload:

Common Events

datagrid-api/error
Emitted when an error occurs during the connection or knowledge creation 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

  1. Event Filtering: Always check that messages are from the expected source and contain the datagrid-api prefix
  2. Error Handling: Implement comprehensive error handling for all possible error scenarios
  3. User Feedback: Provide clear feedback to users about the connection status
  4. Responsive Design: Handle iframe resizing events to provide a smooth user experience
  5. Loading States: Show appropriate loading states while the iframe is initializing

Summary

Quick Reference

Creating a Connection:
Creating Knowledge from Connection: