The Authentication strategy to use (e.g. new BasicAuth())
OptionalbaseUrl: stringThe URL to request (optional in browser, mandatory in node)
Allows to change the current Authentication
The new Authentication information.
StaticauthenticateAuthenticates the given user. Determines the tenant by itself via a call to tenant/currentTenant.
Example
let client: Client;
(async () => {
client = await Client.authenticate({
user: 'testuser',
password: 'password1337!'
}, 'https://acme.cumulocity.com');
//you have access to the client api now
const { data, paging, res }); = await client.inventory.list({ pageSize: 100 });
})();
OptionalbaseUrl: stringStaticauthenticateAuthenticates the given user via OAuth Internal. Determines the tenant by itself via a call to tenant/currentTenant.
Login call goes to /tenant/oauth/token and the retrieved token will be added in the Authorization header to subsequent requests.
Example
let client: Client;
(async () => {
client = await Client.authenticateViaOAuthInternal({
user: 'testuser',
password: 'password1337!'
}, 'https://acme.cumulocity.com');
//you have access to the client api now
const { data, paging, res }); = await client.inventory.list({ pageSize: 100 });
})();
OptionalbaseUrl: stringStaticauthenticateAuthenticates the given user via OAuth Internal. Determines the tenant by itself via a call to tenant/currentTenant.
Login call goes to /tenant/oauth and the retrieved token will be attached as a Cookie in browser environments to subsequent requests (using 'CookieAuth').
In none browser environments (e.g. nodejs) the retrieved token will be added in the Authorization header to subsequent requests (using 'NodeJSCookieAuth').
Example
let client: Client;
(async () => {
client = await Client.authenticateViaOAuthInternalCookie({
user: 'testuser',
password: 'password1337!'
}, 'https://acme.cumulocity.com');
//you have access to the client api now
const { data, paging, res }); = await client.inventory.list({ pageSize: 100 });
})();
OptionalbaseUrl: stringStaticdeviceAllows to use http to register a device on the platform.
Deprecated Please use MQTT to bootstrap a device.
StaticgetRetrieves microservice credentials for the subscribed tenants using provided bootstrap credentials
Example
(async () => {
const subscriptions = await Client.getMicroserviceSubscriptions({
tenant: process.env.C8Y_BOOTSTRAP_TENANT,
user: process.env.C8Y_BOOTSTRAP_USER,
password: process.env.C8Y_BOOTSTRAP_PASSWORD
}, process.env.C8Y_BASEURL);
const clients = subscriptions.map(subscription => new Client(new BasicAuth(subscription), process.env.C8Y_BASEURL));
// you have access to the client api now
const promiseArray = clients.map(client => client.options.tenant.detail({
category: process.env.APPLICATION_KEY,
key: 'someSetting'
}));
})();
StaticloginPerforms the OAuth Internal login.
If the parameter bearerAuth is set to true (default), the /tenant/oauth/token endpoint is called and a string containing the token returned.
If the parameter bearerAuth is set to false, the /tenant/oauth endpoint is called and a Cookie should be set and the response returned.
The response can be used in none browser environments to extract the set-cookie header from it.
Example
(async () => {
const client = await Client.loginViaOAuthInternal({
tenant: process.env.C8Y_BOOTSTRAP_TENANT,
user: process.env.C8Y_BOOTSTRAP_USER,
password: process.env.C8Y_BOOTSTRAP_PASSWORD
}, true, process.env.C8Y_BASEURL);
// you have access to the client api now
const option = client.options.tenant.detail({
category: process.env.APPLICATION_KEY,
key: 'someSetting'
});
})();
OptionalbearerAuth: trueOptionalbaseUrl: stringPerforms the OAuth Internal login.
If the parameter bearerAuth is set to true (default), the /tenant/oauth/token endpoint is called and a string containing the token returned.
If the parameter bearerAuth is set to false, the /tenant/oauth endpoint is called and a Cookie should be set and the response returned.
The response can be used in none browser environments to extract the set-cookie header from it.
Example
(async () => {
const client = await Client.loginViaOAuthInternal({
tenant: process.env.C8Y_BOOTSTRAP_TENANT,
user: process.env.C8Y_BOOTSTRAP_USER,
password: process.env.C8Y_BOOTSTRAP_PASSWORD
}, true, process.env.C8Y_BASEURL);
// you have access to the client api now
const option = client.options.tenant.detail({
category: process.env.APPLICATION_KEY,
key: 'someSetting'
});
})();
OptionalbaseUrl: string
Initializes a new Client, which allows to request data from the API. Differently to Client.authenticate([...]) it needs a tenant given and does not verify if the login is correct.
Example