connectToHostApp once at app startup. It returns a HostAppAPI instance with methods to get the current project, base URL, and access token. Use those credentials to construct a CogniteClient.
For navigation, state, sidebar visibility, fullscreen, and agent integration, see Host App API.
Prerequisites
- A Flows custom app created with
npx @cognite/cli@latest apps create - Basic understanding of React hooks and
useEffect
connectToHostApp
Connects your app to the CDF host window and returns aHostAppAPI instance.
Return value
Example: connect and get project
HostAppAPI credential methods
TheHostAppAPI instance returned by connectToHostApp includes methods for the current project, base URL, and access token. For navigation, state, sidebar visibility, fullscreen, and agent integration, see Host App API.
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
UsegetProject, getBaseUrl, and getAccessToken together to build an authenticated CogniteClient from @cognite/sdk:
Further reading
- Getting started with Flows custom apps — Create your first app
- Run your app locally — Development with authentication
- Flows features — TanStack Query integration with
connectToHostApp