Skip to main content
Authentication and host communication APIs for Flows applications running in CDF. Use these APIs when building Flows custom apps that need authenticated access to CDF resources. The connectToHostApp function establishes communication with the CDF host window and gives you a HostAppAPI instance to retrieve credentials and construct an authenticated Cognite SDK.

Prerequisites

connectToHostApp

Connects your app to the CDF host window and returns a HostAppAPI instance.

Return value

Example: connect and get project

HostAppAPI

The HostAppAPI interface is returned by connectToHostApp and provides methods for interacting with the CDF host.

getProject

Returns the current CDF project name.

getBaseUrl

Returns the base URL of the CDF cluster (for example, https://greenfield.cognitedata.com).

getAccessToken

Returns the current access token for authenticating CDF API calls.

Example: construct a CogniteClient

Use getProject, getBaseUrl, and getAccessToken together to build an authenticated CogniteClient from @cognite/sdk:
Navigates to a path within CDF.
Opens an external URL.

syncInternalState

Saves a serialized state string to the customAppInternalState URL search param. The saved state is passed back as initialState the next time the app mounts. Users can return to the same view after navigating away or refreshing. Because the state lives in the URL, the link is shareable.
See App state in URLs for a full guide covering state restoration, what to include in persisted state, and a complete example.
Last modified on June 24, 2026