Data connectors

The DataConnectorsClient class provides methods to connect an external data provider, such as Google Drive, and manage the resulting connections.

Import limits:

  • Video: Up to 10 GB
  • Audio: Up to 4 GB
  • Images: Up to 32 MB

You can import up to 100 files per request.

Workflow

1

Start the OAuth flow with the data_connectors.authorize_connection method, passing your redirect URL. Redirect the user to the authorization URL you receive. After the user grants access in the browser, the platform redirects them back, with the identifier of the new connection in the connection_id query parameter. Store this identifier.

2

Generate a short-lived access token with the data_connectors.create_connection_picker_token method. Use it with the Google Drive Picker so the user can select files, and store the identifier of each selected file.

3

Import the selected files with the imports.import_files method. Each accepted file becomes an asset in the processing status.

4

Poll the imports.retrieve_import method until each item reaches the ready or failed status. Once an item is ready, use its asset identifier with the rest of the SDK.

5

(Optional) Disconnect the account with the data_connectors.delete_connection method. The platform revokes access and deletes the stored tokens. Assets you already imported are retained.

Methods

Authorize a connection

Description: This method starts the OAuth authorization flow for a data connector. The platform returns an authorization URL. Redirect the user to this URL so they can grant access to their account.

After the user grants or denies access, the platform redirects them to the redirect URL you provided, with the outcome appended to that URL as query parameters. Read these parameters from the redirect that your application receives:

  • connection_id: The identifier of the new connection, returned on success. Store this value and pass it as the connection_id argument in later requests.
  • status: Set to ok on success.
  • custom_id: The label you supplied, returned on success when you provided one.
  • error: An error code, returned instead of the other parameters when the user denies access or the flow fails.

Function signature and example:

1def authorize_connection(
2 self,
3 *,
4 provider: AuthorizeConnectionRequestProvider,
5 redirect_uri: str,
6 custom_id: typing.Optional[str] = OMIT,
7 request_options: typing.Optional[RequestOptions] = None,
8) -> AuthorizeConnectionResponse:

Parameters

NameTypeRequiredDescription
providerAuthorizeConnection
RequestProvider
YesThe data connector provider to authorize. Values: google_drive.
redirect_uristrYesThe URL where the user is redirected after granting or denying access. If your account has an allow-list of redirect URLs configured, this URL must be on it.
custom_idtyping.
Optional[str]
NoA label you supplied, stored on the connection and returned with it. Use a value that does not identify a person so you can match the connection to your own records.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns an AuthorizeConnectionResponse object. The AuthorizeConnectionResponse class contains the following properties:

NameTypeDescription
authorize_urlstrThe URL to redirect the user to so they can grant access.
statestrA value the platform uses to secure the authorization flow. You do not need to read or send it: the platform includes it in the authorize_url field and checks it automatically when the user is redirected back. It is returned only so you can match or troubleshoot requests.

API Reference

Authorize a connection.

List connections

Description: This method returns a list of the connections in your account. The platform returns your connections sorted by creation date, with the newest at the top of the list.

Function signature and example:

1def list_connections(
2 self,
3 *,
4 page: typing.Optional[int] = None,
5 page_limit: typing.Optional[int] = None,
6 request_options: typing.Optional[RequestOptions] = None,
7) -> ListConnectionsResponse:

Parameters

NameTypeRequiredDescription
pagetyping.
Optional[int]
NoA number that identifies the page to retrieve. Default: 1.
page_limittyping.
Optional[int]
NoThe number of items to return on each page. Default: 10. Max: 50.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a ListConnectionsResponse object. The ListConnectionsResponse class contains the following properties:

NameTypeDescription
datatyping.List
[Connection]
An array containing the connections. For the properties of each Connection object, see Retrieve a connection.
page_infoPageInfoAn object that provides information about pagination. Contains the page, limit_per_page, total_page, and total_results fields.

API Reference

List connections.

Retrieve a connection

Description: This method retrieves details about the specified connection.

Function signature and example:

1def retrieve_connection(
2 self,
3 connection_id: str,
4 *,
5 request_options: typing.Optional[RequestOptions] = None,
6) -> Connection:

Parameters

NameTypeRequiredDescription
connection_idstrYesThe unique identifier of the connection to retrieve.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a Connection object. The Connection class contains the following properties:

NameTypeDescription
idstrThe unique identifier of the connection.
providerConnectionProviderThe data connector provider. Values: google_drive.
statusConnectionStatusThe status of the connection. Values: active, expired, revoked.
custom_idstrThe label you supplied when creating the connection. The platform does not interpret this value, and it does not need to be unique. Multiple connections can share the same custom_id value.
accountConnectionAccountInformation about the connected provider account.
scopestyping.List[str]The scopes granted to the connection.
connected_atdatetimeThe date and time, in the RFC 3339 format (“YYYY-MM-DDTHH:mm:ssZ”), when the connection was established.
last_used_atdatetimeThe date and time, in the RFC 3339 format (“YYYY-MM-DDTHH:mm:ssZ”), when the connection was last used.

The ConnectionAccount class contains the following properties:

NameTypeDescription
external_idstrThe identifier of the account at the provider. It does not change.
display_namestrA human-readable label for the account, such as an email address.

API Reference

Retrieve a connection.

Delete a connection

Description: This method disconnects the specified connection. The platform revokes access at the provider and deletes the stored tokens. Assets imported through this connection are retained.

Function signature and example:

1def delete_connection(
2 self,
3 connection_id: str,
4 *,
5 request_options: typing.Optional[RequestOptions] = None,
6) -> None:

Parameters

NameTypeRequiredDescription
connection_idstrYesThe unique identifier of the connection to delete.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

This method does not return a value.

API Reference

Delete a connection.

Generate a picker token

Description: This method generates a short-lived, read-only access token that you use with the provider’s file picker, such as the Google Drive Picker. The platform never returns the refresh token of the connection.

Function signature and example:

1def create_connection_picker_token(
2 self,
3 connection_id: str,
4 *,
5 request_options: typing.Optional[RequestOptions] = None,
6) -> CreateConnectionPickerTokenResponse:

Parameters

NameTypeRequiredDescription
connection_idstrYesThe unique identifier of the connection.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a CreateConnectionPickerTokenResponse object. The CreateConnectionPickerTokenResponse class contains the following properties:

NameTypeDescription
access_tokenstrA short-lived, read-only access token for use with the provider’s file picker.
expires_inintThe number of seconds until the token expires.
scopestrA space-delimited list of the scopes granted to the token.
app_idstrThe Google Cloud project number, used with the Google Picker’s setAppId. May be absent if the provider does not require this value for its picker.
developer_keystrA browser API key, used with the Google Picker’s setDeveloperKey. May be absent if the provider does not require this value for its picker.

API Reference

Generate a picker token.