### Install Dependencies and Start Dev Server Source: https://docs.cognite.com/cdf/flows/guides/getting-started Install project dependencies and start the local development server. This process may require trusting a self-signed certificate on the first run. ```bash npm install npm start ``` -------------------------------- ### Web Quickstart: Authenticate and List Assets Source: https://docs.cognite.com/dev/sdks/js A quickstart example for web applications using OAuth for authentication. It demonstrates how to initialize the client and fetch a list of assets. ```javascript import { CogniteClient } from '@cognite/sdk'; async function quickstart() { const client = new CogniteClient({ appId: 'YOUR APPLICATION NAME' }); client.loginWithOAuth({ project: 'publicdata', }); const assets = await client.assets.list().autoPagingToArray({ limit: 100 }); } quickstart(); ``` -------------------------------- ### Backend Quickstart: Authenticate with Client Credentials and List Assets Source: https://docs.cognite.com/dev/sdks/js A quickstart example for backend applications using client credentials for authentication with Azure AD. It shows how to set up the client and retrieve assets. ```javascript import { ConfidentialClientApplication } from "@azure/msal-node"; import { CogniteClient } from "@cognite/sdk"; async function quickstart() { const pca = new ConfidentialClientApplication({ auth: { clientId: 'YOUR CLIENT ID', clientSecret: 'YOUR CLIENT SECRET', authority: 'INSERT AUTHORITY HERE' } }); async function getToken() { var response = await pca.acquireTokenByClientCredential({ scopes: ['INSERT SCOPE HERE'], skipCache: true, }); return response.accessToken; } const client = new CogniteClient({ appId: 'Cognite SDK samples', baseUrl: 'YOUR BASE URL', project: 'YOUR CDF PROJECT NAME', getToken: getToken }); const assets = await client.assets.list(); console.log(assets); } quickstart(); ``` -------------------------------- ### Example GET Request Source: https://docs.cognite.com/cdf/dashboards/references/odata/index An example GET request to retrieve all assets in a project. ```APIDOC ## Example GET request To retrieve all assets in a project: ``` GET https://{cluster}.cognitedata.com/odata/{apiVersion}/projects/{project}/Assets ``` Where: * `{cluster}`: The CDF cluster name (e.g., westeurope-1). * `{apiVersion}`: The OData service API version (e.g., v1). * `{project}`: Your CDF project name. ``` -------------------------------- ### Install NEAT and Jupyter Lab on Windows Source: https://docs.cognite.com/cdf/deploy/neat/installation Commands to set up a local Python virtual environment, install necessary packages (cognite-neat, jupyterlab, tqdm), and start Jupyter Lab on a Windows machine. ```bash mkdir neat && cd neat python -m venv venv venv\Scripts\activate.bat pip install cognite-neat pip install jupyterlab pip install tqdm jupyter lab ``` -------------------------------- ### Install NEAT and Jupyter Lab on Mac/Linux Source: https://docs.cognite.com/cdf/deploy/neat/installation Commands to set up a local Python virtual environment, install necessary packages (cognite-neat with pyoxigraph support, jupyterlab, tqdm), and start Jupyter Lab on a Mac or Linux machine. ```bash mkdir neat && cd neat python -m venv venv source venv/bin/activate pip install "cognite-neat[pyoxigraph]" pip install jupyterlab pip install tqdm jupyter lab ``` -------------------------------- ### Simple Cursor Example: Fetching Assets Source: https://docs.cognite.com/dev/concepts/pagination Demonstrates a GET request to fetch assets with a limit and the structure of the response including `nextCursor` and `items`. ```json HTTP GET /assets?limit=1 { "nextCursor": "8ZiApWzGe5RnTAE1N5SABLDNv7GKkUGiVUyUjzNsDvM", "items": [ { "name": "23-TE-96116-04", "parentId": 3117826349444493, "description": "VRD - PH 1STSTGGEAR THRUST BRG OUT", "metadata": { "ELC_STATUS_ID": "1211", "RES_ID": "525283" }, "id": 702630644612, "createdTime": 0, "lastUpdatedTime": 0, "rootId": 6687602007296940 } ] } ``` -------------------------------- ### Initialize Configuration Files and Modules Source: https://docs.cognite.com/cdf/deploy/cdf_toolkit/guides/setup Run this command to initialize the configuration files and modules for your Cognite Data Fusion organization. This starts an interactive setup process. ```shell cdf modules init ``` -------------------------------- ### Install Node.js on Windows Source: https://docs.cognite.com/cdf/flows/guides/getting-started Instructions for installing Node.js on Windows by downloading the installer from the official Node.js website. ```bash # Download the installer from https://nodejs.org/ ``` -------------------------------- ### MQTT Source Configuration Source: https://docs.cognite.com/cdf/deploy/cdf_toolkit/references/resource_library Example of a source configuration file for an MQTT v5 connection. Ensure Cognite Toolkit v0.3.0 or later is installed. ```yaml type: mqtt5 externalId: my_mqtt host: mqtt.example.com port: 1883 authentication: username: myuser password: ${my_mqtt_password} ``` -------------------------------- ### Install Node.js using nvm Source: https://docs.cognite.com/cdf/flows/guides/getting-started Recommended method for installing and managing Node.js versions. Ensure nvm is loaded before installing Node.js. ```bash # Download and install nvm: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash # Load nvm (or restart your terminal): . "$HOME/.nvm/nvm.sh" # Install Node.js: nvm install 20.19.5 ``` -------------------------------- ### Iterate Assets with Partitions Source: https://docs.cognite.com/dev/sdks/python/changelog Example demonstrating how to use the `partitions` parameter for generator-based asset listing. ```python for asset in client.assets(partitions=10): # do something ``` -------------------------------- ### Install Cognite SDK with Functions Dependency Source: https://docs.cognite.com/dev/sdks/python/changelog To use the optional functions dependency, install the SDK with the specified extra. This enables additional functionality related to Cognite Functions. ```bash pip install "cognite-sdk[functions]" ``` -------------------------------- ### Datapoints Query Class Example Source: https://docs.cognite.com/dev/sdks/python/changelog Demonstrates the transition from dictionary-based datapoint queries to the new DatapointsQuery class for improved type safety and robustness. ```python {"id": 12, "aggregates" : "min", "granularity": "6h"} -> DatapointsQuery(id=12, aggregates="min", granularity="6h") ``` -------------------------------- ### Filter TimeSeries with Sort Parameter Source: https://docs.cognite.com/dev/sdks/python/changelog This example shows the correct usage of `time_series.filter()` with a `sort` parameter to avoid potential errors. ```python client.time_series.filter(sort=["name"]) ``` -------------------------------- ### Run the Quickstart Package Source: https://docs.cognite.com/cdf/deploy/cdf_toolkit/references/packages/quickstart Execute the quickstart method on the toolkit instance with your organization, client ID, and client secret to initialize, build, and deploy the quickstart modules. ```python toolkit.quickstart(my_organization, client_id, client_secret) ``` -------------------------------- ### Import NEAT and get Cognite Client Source: https://docs.cognite.com/cdf/deploy/neat/tutorials/introduction Import the NeatSession class and the get_cognite_client function. Use get_cognite_client to establish a connection to CDF, which can pick up credentials from a .env file or guide through setup. ```python from cognite.neat import NeatSession, get_cognite_client client = get_cognite_client(".env") ``` -------------------------------- ### Cognite CLI AI Skills Examples Source: https://docs.cognite.com/dev/sdks/cognite-cli/reference These examples demonstrate common invocations for managing AI skills, including pulling all skills, pulling a specific skill, and listing installed skills. ```bash npx @cognite/cli@latest apps skills pull # Pull all skills ``` ```bash npx @cognite/cli@latest apps skills pull --skill create-client-tool # Pull a specific skill ``` ```bash npx @cognite/cli@latest apps skills list # List installed skills ``` -------------------------------- ### Example Database Configurations Source: https://docs.cognite.com/cdf/integration/guides/extraction/configuration/db Demonstrates how to configure connections for multiple databases, including ODBC and PostgreSQL. Shows different authentication and source configuration options. ```yaml databases: - type: odbc name: my-odbc-database connection-string: DRIVER={Oracle 19.3};DBQ=localhost:1521/XE;UID=SYSTEM;PWD=oracle - type: postgres name: postgres-db host: pg.company.com user: postgres password: secret123Pas$word - type: postgres name: postgres-db host: pg.company.com user: postgres password: secret123Pas$word source: name: test_source external-id: test_source_id_1 ``` -------------------------------- ### Example GET Request to Retrieve Assets Source: https://docs.cognite.com/cdf/dashboards/references/odata Make an HTTP GET request to the OData endpoint to retrieve all assets in a project. Replace placeholders with your cluster, API version, and project name. ```http GET https://{cluster}.cognitedata.com/odata/{apiVersion}/projects/{project}/Assets ``` -------------------------------- ### Example config.[env].yaml File Source: https://docs.cognite.com/cdf/deploy/cdf_toolkit/api/config_yaml This example demonstrates the structure of a typical config.[env].yaml file, including environment settings and module configurations. ```yaml environment: name: dev project: demo type: dev selected: - modules/ variables: modules: cdf_ingestion: workflow: ingestion groupSourceId: b89b117a-9f2e-4588-b7dc-bee39f2258d8 pandidContextualizationFunction: contextualization_p_and_id_annotater contextualization_connection_writer: contextualization_connection_writer instanceSpaces: - springfield_instances - cdf_cdm_units ``` -------------------------------- ### Configure Credentials for Quickstart Source: https://docs.cognite.com/cdf/deploy/cdf_toolkit/references/packages/quickstart Define variables for your organization name, client ID, and client secret. These are required for authenticating and running the quickstart package. ```python # This is used in the extension of the Cognite Process Indusdry Model my_organization = "" client_id = "" # The client ID of the service account client_secret = "" # The client secret of the service account ``` -------------------------------- ### Example Temperature Distribution Response Source: https://docs.cognite.com/cdf/dm/records/guides/records_aggregations This is an example JSON response for a temperature distribution aggregation. It shows the structure of the 'numberHistogramBuckets' array, detailing the start of each interval and the count of events within that interval. ```json { "aggregates": { "temp_distribution": { "numberHistogramBuckets": [ { "intervalStart": 0, "count": 12 }, { "intervalStart": 20, "count": 45 }, { "intervalStart": 40, "count": 178 }, { "intervalStart": 60, "count": 412 }, { "intervalStart": 80, "count": 356 }, { "intervalStart": 100, "count": 168 }, { "intervalStart": 120, "count": 0 }, { "intervalStart": 140, "count": 62 }, { "intervalStart": 160, "count": 17 } ] } } } ``` -------------------------------- ### Install create-react-app Source: https://docs.cognite.com/dev/sdks/js Install the create-react-app tool to set up your React application and navigate into the project directory. ```bash npx create-react-app hello-world cd hello-world ``` -------------------------------- ### Module Configuration Example Source: https://docs.cognite.com/cdf/deploy/cdf_toolkit/guides/usage Example of a module configuration file, specifying environment details and selected modules for deployment. ```yaml environment: name: dev project: validation-type: dev selected: - cdf_demo_infield - cdf_oid_example_data ``` -------------------------------- ### Cognite CLI Apps Create Examples Source: https://docs.cognite.com/dev/sdks/cognite-cli/reference Demonstrates various ways to invoke the `apps create` command, from interactive to fully non-interactive for CI/AI agents. ```bash # Interactive npx @cognite/cli@latest apps create ``` ```bash # Target subdirectory npx @cognite/cli@latest apps create my-app ``` ```bash # Fully non-interactive (CI/AI agents) npx @cognite/cli@latest apps create my-app \ --display-name "My App" \ --description "My app" \ --org cog-atlas \ --project atlas-greenfield \ --cluster greenfield \ --base-url https://greenfield.cognitedata.com ``` -------------------------------- ### Retrieve Single Time Series Datapoints Example Source: https://docs.cognite.com/cdf/dashboards/references/rest/powerbi_rest_examples Example of how to use the RetrieveDataPoints function to fetch data for a single time series. This demonstrates basic usage with specified start and end times, aggregates, and granularity. ```M let Source = RetrieveDataPoints( [ externalId = "EVE-TI-FORNEBU-01-3" ], #datetimezone(2024, 10, 1, 0, 0, 0, 2, 0), #datetimezone(2024, 10, 13, 10, 0, 0, 2, 0), "average,max,min", "1d", null, "SI", "Europe/Oslo", null ) in Source ``` -------------------------------- ### Install mkcert on Windows using Scoop Source: https://docs.cognite.com/cdf/flows/guides/local-https Add the 'extras' bucket and install mkcert using the Scoop package manager on Windows. ```bash scoop bucket add extras scoop install mkcert ``` -------------------------------- ### Initialize Azure DevOps Pipelines Source: https://docs.cognite.com/cdf/deploy/cdf_toolkit/guides/cicd/ado_setup Run these commands to generate example pipeline configuration files for Azure DevOps. Select Azure DevOps as the CI/CD provider when prompted. ```bash git switch -c add-ado-pipelines cdf repo init ``` -------------------------------- ### Reduce List to Single Value (Product) Source: https://docs.cognite.com/cdf/integration/guides/extraction/hosted_extractors/built_in_functions This `reduce` example calculates the product of all list elements, starting with an initial accumulator of 1. ```kuiper [1, 2, 3, 4, 5].reduce((acc, val) => acc * val, 1) -> 120 ``` -------------------------------- ### Deploy and Sign Application Source: https://docs.cognite.com/cdf/flows/guides/application-certification Deploy your application by building and uploading it, then sign the bundle. Ensure your working tree is clean before deploying. ```bash npx @cognite/cli@latest apps deploy ``` ```bash npx @cognite/cli@latest apps sign ``` -------------------------------- ### Authenticate Client with OAuth Source: https://docs.cognite.com/dev/sdks/js/migration Alternatively, authenticate the SDK client using OAuth. This example shows the basic setup for OAuth authentication. ```javascript client.loginWithOAuth({ project: 'publicdata', }); ``` -------------------------------- ### Build and Deploy App Source: https://docs.cognite.com/cdf/flows/guides/code-signing Build your application and deploy it as a draft. This command packages your distribution files and uploads them to the platform, storing a zip of the bundle locally. ```bash npm run build npx @cognite/cli@latest apps deploy --interactive ``` -------------------------------- ### Regex Validation for External IDs Source: https://docs.cognite.com/cdf/deploy/reference/cdf_resource_naming_conventions Example regex pattern for CI/CD linting to validate external IDs, ensuring they start with 'ep_' and use snake_case. ```regex ^ep_[a-z0-9]+_[a-z0-9]+$ ``` -------------------------------- ### Activate Poetry Shell Source: https://docs.cognite.com/cdf/deploy/cdf_toolkit/guides/upgrade Activate your Poetry virtual environment by starting a new shell session. This is necessary to ensure commands recognize the installed toolkit version. ```sh poetry shell ``` -------------------------------- ### Configure Plugin Entry Points in pyproject.toml Source: https://docs.cognite.com/cdf/deploy/neat/reference/alpha_flags Example of how to configure entry points for a custom Neat plugin in the `pyproject.toml` file. This allows Neat to discover and load the plugin. ```toml ... [project.entry-points."cognite.neat.plugin.data_model.readers"] external_excel = "my_plugin:ExcelDataModelImporterPlugin" ... ``` -------------------------------- ### Retrieve Data Points with Multiple Granularities and Common Settings Source: https://docs.cognite.com/dev/concepts/aggregation/calendar This example shows how to retrieve data points for multiple time series with different granularities but a common start time, aggregate function, and time zone. Note that the start time is rounded down based on the granularity and time zone. ```json POST /api/v1/projects/{project}/timeseries/data/list Content-Type: application/json { "items": [ { "externalId": "your external id", "granularity": "1day" }, { "externalId": "your external id", "granularity": "6h" } ], "start": 1582144200000, "aggregates": ["count"], "timeZone": "UTC+01:00", "limit": 1 } Response: { "items": [ { "id": 123, "externalId": "your external id", "isString": false, "isStep": false, "datapoints": [ { "timestamp": 1582066800000, "count": 2 } ] }, { "id": 123, "externalId": "your external id", "isString": false, "isStep": false, "datapoints": [ { "timestamp": 1582142400000, "count": 5 } ] } ] } ``` -------------------------------- ### PostgreSQL Database Configuration Example Source: https://docs.cognite.com/cdf/integration/guides/extraction/configuration/db Example configuration for connecting to a PostgreSQL database. Ensure the 'type' is set to 'postgres' and provide connection details like host, user, and password. ```yaml type: postgres name: my-database host: 10.42.39.12 user: extractor-user password: mySecretPassword ``` -------------------------------- ### Get Minimum Value for Properties Source: https://docs.cognite.com/cdf/dm/records/guides/records_aggregations Use the 'min' aggregation to find the lowest value for 'temperature' and 'lastUpdatedTime' properties. This example demonstrates filtering records and specifying aggregate calculations. ```curl curl -X POST \ "https://${CLUSTER}.cognitedata.com/api/v1/projects/${PROJECT}/streams/${STREAM_ID}/records/aggregate" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${TOKEN}" \ -d '{ \ "lastUpdatedTime": { "gt": "2025-10-01T00:00:00.000Z" }, \ "filter": { \ "hasData": [{ \ "type": "container", \ "space": "factory-data", \ "externalId": "equipment_events" \ }] \ }, \ "aggregates": { \ "coldest_reading": { \ "min": { \ "property": ["factory-data", "equipment_events", "temperature"] \ } \ }, \ "earliest_event": { \ "min": { \ "property": ["lastUpdatedTime"] \ } \ } \ } \ }' ``` -------------------------------- ### Reduce List to Single Value (Sum) Source: https://docs.cognite.com/cdf/integration/guides/extraction/hosted_extractors/built_in_functions Use `reduce` with an accumulator and a lambda function to aggregate list elements. This example sums all elements starting with an initial accumulator of 0. ```kuiper [1, 2, 3, 4, 5].reduce((acc, val) => acc + val, 0) -> 15 ```