Nupital Pomp Mesmerises

    @cognite/sdk
    TypeScript icon, indicating that this package has built-in type declarations

    7.8.2 • Public • Published

    Cognite Javascript SDK

    The package @cognite/sdk provides convenient access to the stable Cognite API from applications written in client- or server-side javascript.

    The SDK supports authentication through api-keys (for server-side applications) and bearer tokens (for web applications). See Authentication Guide.

    Installation

    Video quickstart
    Cognite JS SDK video guide

    Install the package with yarn:

    $ yarn add @cognite/sdk
    

    or npm

    $ npm install @cognite/sdk --save
    

    Usage

    const { CogniteClient } = require('@cognite/sdk');

    Using ES modules

    import { CogniteClient } from '@cognite/sdk';

    Using typescript

    The SDK is written in native typescript, so no extra types need to be defined.

    Quickstart

    Web

    import { CogniteClient, CogniteAuthentication } from '@cognite/sdk';
    
    async function quickstart() {
    
    const project = "publicdata";
    const legacyInstance = new CogniteAuthentication({
      project,
    });
    
    const getToken = async () => {
      await legacyInstance.handleLoginRedirect();
      let token = await legacyInstance.getCDFToken();
      if (token) {
        return token.accessToken;
      }
      token = await legacyInstance.login({ onAuthenticate: "REDIRECT" });
      if (token) {
        return token.accessToken;
      }
      throw new Error("error");
    };
    
    
      const client = new CogniteClient({
        appId: 'YOUR APPLICATION NAME',
        project,
        getToken
      });
    
      const assets = await client.assets
        .list()
        .autoPagingToArray({ limit: 100 });
    }
    quickstart();

    For more details about SDK authentication see this document. Also, more comprehensive intro guide with a demo app can be found here

    Backend

    const { CogniteClient } = require('@cognite/sdk');
    
    async function quickstart() {
      const client = new CogniteClient({
        appId: 'YOUR APPLICATION NAME',
        apiKeyMode: true,
        getToken: () => Promise.resolve('YOUR_SECRET_API_KEY')
      });
    
      const assets = await client.assets
        .list()
        .autoPagingToArray({ limit: 100 });
    }
    quickstart();

    Documentation

    Best practices

    No submodule imports

    We highly recommend avoiding importing anything from internal SDK modules.

    All interfaces and functions should only be imported from the top level, otherwise you might face compatibility issues when our internal structure changes.

    Bad:

    import { CogniteAsyncIterator } from '@cognite/sdk/dist/src/autoPagination'; // ❌
    import { AssetsAPI } from '@cognite/sdk/dist/src/resources/assets/assetsApi'; // ❌
    
    let assetsApi: AssetsAPI; // ❌
    

    Good:

    import { CogniteAsyncIterator } from '@cognite/sdk'; // ✅
    
    let assetsApi: CogniteClient['assets']; // ✅
    

    We recommend the usage of eslint to ensure this best practice is enforced without having to memorize the patterns:

    .eslintrc.json:

    "rules": {
      "no-restricted-imports": ["error", { "patterns": ["@cognite/sdk/**"] }]
    }
    

    The API reference documentation contains snippets for each endpoint, giving examples of SDK use. See also the samples section in this repo.

    Guides

    Keywords

    none

    Install

    npm i @cognite/sdk

    DownloadsWeekly Downloads

    3,960

    Version

    7.8.2

    License

    Apache-2.0

    Unpacked Size

    509 kB

    Total Files

    59

    Last publish

    Collaborators

    • vincent-cognite
    • joelnicolaysen-cognite
    • shashan_udawatte
    • kanchana.premachandra
    • dilesha08
    • mhmdfy
    • emircognite
    • simenkristoffersen
    • emmacognite
    • erik.galler
    • jens.kristoffersen
    • redzarosli
    • evertoncolling
    • rastif
    • asankad.cog
    • tokongs
    • cognite.harbs
    • queenie-cognite
    • sig1991
    • mlkrsrc
    • ahmedcognite
    • kondanta
    • bkuzma
    • shubhski
    • stefanmaretic
    • maksym.kowalski
    • bdemirel
    • toonday
    • sennen-cognite
    • eiriklv
    • dmakked
    • caner-cognite
    • 23andreas
    • ikechukwu
    • astridkg
    • marcelo_costa
    • fran.hrzenjak
    • torgrim
    • wchatx
    • julia.scott
    • marvin.reza
    • einar.omang
    • bhavith
    • oleksandr.kolomiiets
    • dafn
    • erlendvollset
    • eirik.djuve
    • luka-mikec-cognite
    • sou1est
    • sagarthalwar
    • martin-wahlberg
    • nabati
    • kinga.cognite
    • borlov
    • cyriaquebrousse
    • tugceozgur
    • erikangelsen-cognite
    • ankku
    • silvavelosa
    • henrist
    • robinhoodie
    • peet.cremer
    • ponnapz
    • shekhardesigner
    • kornelione
    • greenbech-cognite
    • lpereiracgn
    • manoj-cognite
    • oiuytrdsxcvbnjkhgfcvbnm
    • wjoel
    • tapped
    • sumitpandey
    • francisco.rull
    • frxstrem
    • cognitecicd
    • parami.abeysekara
    • cemreyavuz
    • neringaalt
    • rhuan.barreto
    • funsim
    • pavelzubarev
    • msusag
    • nfremming
    • steinhdan
    • dmivankov
    • polomani
    • simen.eriksen
    • nils-cognite
    • dlcognite
    • haak
    • carlospereira
    • larsmoa
    • nishafern
    • trygve.utstumo
    • kathrine-cognite
    • rekarnar
    • maximcognite
    • vegardokland
    • hhenriques
    • tfheen-cognite
    • oksana_korniienko
    • j-bjorne
    • scottmelhop
    • mathialo
    • agadacz-cognite
    • paulo-menezes-cognite
    • miladcognite
    • me-ydv-5
    • cogniteterraform
    • anderscognite
    • fredrik955
    • halvard
    • dan.levings.cognite
    • sindresh92
    • christjt
    • maksim.nesterenko
    • hakontro
    • arnekv
    • ana-gheorghe
    • judeezzz
    • dilinifernando
    • mithilacognite
    • maneshka.cognite
    • vdb93
    • eriklien
    • padalby
    • jorglund
    • tuanng-cognite
    • digaomilleniun.cognite
    • cognite-ornellas
    • harish0489
    • pedro.lindeza
    • abdullah-cognite
    • davidhwu
    • anjalirai2626
    • d0ttir
    • filipjohnsen
    • omarakabbal
    • savokr
    • pramodcog
    • tharindudg
    • brgverst
    • thorkild
    • sigridschaanning
    • smartalas
    • arnels
    • sondre.solbakken
    • pbettler
    • qtiptip
    • sceniclife
    • johan-cognite
    • theresatalor-cognite
    • mspang
    • eliasbjorne
    • oysteinolsen
    • anders-cog
    • skairunner
    • jtcog
    • petmotzf
    • deep-cognite
    • mattmurph9
    • lprovensi
    • haakonflatval-cognite
    • begozcan
    • khalzmax
    • chingyu-cognite
    • sighol
    • heiding
    • ronald-cognite
    • daniel.priori
    • ravinda-cognite
    • timurgen
    • trodden-dev
    • emel.varol
    • bdimitrijoski
    • madskjeldsberg
    • yevhenii.maltsev
    • farrukk24
    • aurlien
    • bianca-mv
    • samarv
    • soleh23
    • malindakpt
    • mihilr
    • gayandeegala
    • tfarvac
    • borajimin
    • samir-ajdarpasic
    • torbjornopheim
    • chanaka25
    • geircognite
    • soumesh.banerjee
    • mohsin.cognite
    • vebjorngilberg
    • roligheten
    • marcushorn
    • sara.aalbu
    • atussa
    • aizumi
    • therockvalley
    • dmitrijs.rutko.cognite
    • perarnet
    • bisera
    • shehan.cognite
    • udara-cognite
    • raabyeeggs
    • jarlah
    • keepfloyding
    • cgustad
    • tommy_thorsen
    • andersfylling
    • meisammalekzadeh
    • ericbrattli
    • mcarun
    • saagar-cognite
    • waqasjaved1