Create a new SDK client
Client options
import { CogniteClient } from '@cognite/sdk';
const client = new CogniteClient({ appId: 'YOUR APPLICATION NAME' });
// can also specify a base URL
const client = new CogniteClient({ ..., baseUrl: 'https://greenfield.cognitedata.com' });
Basic HTTP method for DELETE
The URL path
Request options, optional
const response = await client.delete('someUrl');
Basic HTTP method for GET
The URL path
Request options, optional
const response = await client.get('/api/v1/projects/{project}/assets', { params: { limit: 50 }});
Returns the base-url used for all requests.
Returns the default HTTP request headers, including e.g. authentication headers that is included in all requests. Headers provided per-requests is not included in this list. This function is useful when constructing API requests outside the SDK.
const customUrl = '...';
const headers = client.getDefaultRequestHeaders();
const result = await fetch(customUrl, { headers });
Lookup response metadata from an request using the response as the parameter
const createdAsset = await client.assets.create([{ name: 'My first asset' }]);
const metadata = client.getMetadata(createdAsset);
Basic HTTP method for PATCH
The URL path
Request options, optional
const response = await client.patch('someUrl');
Basic HTTP method for POST
The URL path
Request options, optional
const assets = [{ name: 'First asset' }, { name: 'Second asset' }];
const response = await client.post('/api/v1/projects/{project}/assets', { data: { items: assets } });
Basic HTTP method for PUT
The URL path
Request options, optional
const response = await client.put('someUrl');
SDK client (beta)
For smooth transition between stable sdk and beta, you may create an alias
"@cognite/sdk": "@cognite/sdk-beta@^<version>"
inpackage.json
The beta SDK exports the client with the same name as stable, meaning you don't need to change any imports.import { CogniteClient } from '@cognite/sdk'; const client = new CogniteClient({ appId: 'YOUR APPLICATION NAME' }); // can also specify a base URL const client = new CogniteClient({ ..., baseUrl: 'https://greenfield.cognitedata.com' });
Client options