Welcome to the Resin SDK documentation.
This document aims to describe all the functions supported by the SDK, as well as showing examples of their expected usage.
If you feel something is missing, not clear or could be improved, please don't hesitate to open an issue in GitHub, we'll be happy to help.
Kind: global namespace
- resin :
object
- .interceptors :
Array.<Interceptor>
- .Interceptor :
object
- .Interceptor :
- .request :
Object
- .pine :
Object
- .errors :
Object
- .models :
object
- .application :
object
- .tags :
object
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAll([options]) ⇒
Promise
- .set(nameOrId, tagKey, value) ⇒
Promise
- .remove(nameOrId, tagKey) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
- .getAll([options]) ⇒
Promise
- .get(nameOrId, [options]) ⇒
Promise
- .getAppByOwner(appName, owner, [options]) ⇒
Promise
- .has(nameOrId) ⇒
Promise
- .hasAny() ⇒
Promise
.getById(id) ⇒Promise
- .create(name, deviceType, [parentNameOrId]) ⇒
Promise
- .remove(nameOrId) ⇒
Promise
- .restart(nameOrId) ⇒
Promise
- .generateApiKey(nameOrId) ⇒
Promise
- .generateProvisioningKey(nameOrId) ⇒
Promise
- .purge(appId) ⇒
Promise
- .shutdown(appId, [options]) ⇒
Promise
- .reboot(appId, [options]) ⇒
Promise
- .enableDeviceUrls(nameOrId) ⇒
Promise
- .disableDeviceUrls(nameOrId) ⇒
Promise
- .grantSupportAccess(nameOrId, expiryTimestamp) ⇒
Promise
- .revokeSupportAccess(nameOrId) ⇒
Promise
- .tags :
- .device :
object
- .tags :
object
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAllByDevice(uuidOrId, [options]) ⇒
Promise
- .getAll([options]) ⇒
Promise
- .set(uuidOrId, tagKey, value) ⇒
Promise
- .remove(uuidOrId, tagKey) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
- .getDashboardUrl(uuid) ⇒
String
- .getAll([options]) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAllByParentDevice(parentUuidOrId, [options]) ⇒
Promise
- .get(uuidOrId, [options]) ⇒
Promise
- .getByName(name) ⇒
Promise
- .getName(uuidOrId) ⇒
Promise
- .getApplicationName(uuidOrId) ⇒
Promise
- .getApplicationInfo(uuidOrId) ⇒
Promise
- .has(uuidOrId) ⇒
Promise
- .isOnline(uuidOrId) ⇒
Promise
- .getLocalIPAddresses(uuidOrId) ⇒
Promise
- .remove(uuidOrId) ⇒
Promise
- .identify(uuidOrId) ⇒
Promise
- .rename(uuidOrId, newName) ⇒
Promise
- .note(uuidOrId, note) ⇒
Promise
- .setCustomLocation(uuidOrId, location) ⇒
Promise
- .unsetCustomLocation(uuidOrId) ⇒
Promise
- .move(uuidOrId, applicationNameOrId) ⇒
Promise
- .startApplication(uuidOrId) ⇒
Promise
- .stopApplication(uuidOrId) ⇒
Promise
- .restartApplication(uuidOrId) ⇒
Promise
- .reboot(uuidOrId, [options]) ⇒
Promise
- .shutdown(uuidOrId, [options]) ⇒
Promise
- .purge(uuidOrId) ⇒
Promise
- .update(uuidOrId, [options]) ⇒
Promise
- .getDisplayName(deviceTypeSlug) ⇒
Promise
- .getDeviceSlug(deviceTypeName) ⇒
Promise
- .getSupportedDeviceTypes() ⇒
Promise
- .getManifestBySlug(slug) ⇒
Promise
- .getManifestByApplication(nameOrId) ⇒
Promise
- .generateUniqueKey() ⇒
String
- .register(applicationNameOrId, [uuid]) ⇒
Promise
- .generateDeviceKey(uuidOrId) ⇒
Promise
- .hasDeviceUrl(uuidOrId) ⇒
Promise
- .getDeviceUrl(uuidOrId) ⇒
Promise
- .enableDeviceUrl(uuidOrId) ⇒
Promise
- .disableDeviceUrl(uuidOrId) ⇒
Promise
- .enableTcpPing(uuidOrId) ⇒
Promise
- .disableTcpPing(uuidOrId) ⇒
Promise
- .ping(uuidOrId) ⇒
Promise
- .getStatus(device) ⇒
Promise
- .grantSupportAccess(uuidOrId, expiryTimestamp) ⇒
Promise
- .revokeSupportAccess(uuidOrId) ⇒
Promise
- .lastOnline(device) ⇒
String
- .tags :
- .key :
object
- .getAll([options]) ⇒
Promise
- .get(id) ⇒
Promise
- .remove(id) ⇒
Promise
- .create(title, key) ⇒
Promise
- .getAll([options]) ⇒
- .environment-variables :
object
- .device :
object
- .getAll(uuidOrId) ⇒
Promise
- .getAllByApplication(nameOrId) ⇒
Promise
- .create(uuidOrId, envVarName, value) ⇒
Promise
- .update(id, value) ⇒
Promise
- .remove(id) ⇒
Promise
- .getAll(uuidOrId) ⇒
- .getAllByApplication(applicationNameOrId) ⇒
Promise
- .create(applicationNameOrId, envVarName, value) ⇒
Promise
- .update(id, value) ⇒
Promise
- .remove(id) ⇒
Promise
- .isSystemVariable(variable) ⇒
Boolean
- .device :
- .os :
object
- .getDownloadSize(deviceType, [version]) ⇒
Promise
- .getSupportedVersions(deviceType) ⇒
Promise
- .getMaxSatisfyingVersion(deviceType, versionOrRange) ⇒
Promise
- .getLastModified(deviceType, [version]) ⇒
Promise
- .download(deviceType, [version]) ⇒
Promise
- .getConfig(nameOrId, [options]) ⇒
Promise
- .getDownloadSize(deviceType, [version]) ⇒
- .config :
object
- .getAll() ⇒
Promise
- .getDeviceTypes() ⇒
Promise
- .getDeviceOptions(deviceType) ⇒
Promise
- .getAll() ⇒
- .build :
object
- .get(id, [options]) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .get(id, [options]) ⇒
- .billing :
object
- .getAccount() ⇒
Promise
- .getPlan() ⇒
Promise
- .getBillingInfo() ⇒
Promise
- .updateBillingInfo() ⇒
Promise
- .getInvoices() ⇒
Promise
- .downloadInvoice() ⇒
Promise
- .getAccount() ⇒
- .application :
- .auth :
object
- .twoFactor :
object
- .isEnabled() ⇒
Promise
- .isPassed() ⇒
Promise
- .challenge(code) ⇒
Promise
- .isEnabled() ⇒
- .whoami() ⇒
Promise
- .authenticate(credentials) ⇒
Promise
- .login(credentials) ⇒
Promise
- .loginWithToken(authToken) ⇒
Promise
- .isLoggedIn() ⇒
Promise
- .createApiKey(name) ⇒
Promise
- .getToken() ⇒
Promise
- .getUserId() ⇒
Promise
- .getEmail() ⇒
Promise
- .logout() ⇒
Promise
- .register([credentials]) ⇒
Promise
- .twoFactor :
- .logs :
object
- .subscribe(uuidOrId) ⇒
Promise
- .history(uuidOrId, [options]) ⇒
Promise
- .historySinceLastClear(uuidOrId, [options]) ⇒
Promise
- .clear(uuidOrId) ⇒
Promise
- .LogSubscription :
EventEmitter
- .subscribe(uuidOrId) ⇒
- .settings :
object
- .get([key]) ⇒
Promise
- .getAll() ⇒
Promise
- .get([key]) ⇒
- .setSharedOptions()
- .fromSharedOptions()
- .interceptors :
The current array of interceptors to use. Interceptors intercept requests made internally and are executed in the order they appear in this array for requests, and in the reverse order for responses.
Kind: static property of resin
Summary: Array of interceptors
Access: public
Example
resin.interceptors.push({
responseError: function (error) {
console.log(error);
throw error;
})
});
An interceptor implements some set of the four interception hook callbacks. To continue processing, each function should return a value or a promise that successfully resolves to a value.
To halt processing, each function should throw an error or return a promise that rejects with an error.
Kind: static typedef of interceptors
Properties
Name | Type | Description |
---|---|---|
request | function |
Callback invoked before requests are made. Called with the request options, should return (or resolve to) new request options, or throw/reject. |
response | function |
Callback invoked before responses are returned. Called with the response, should return (or resolve to) a new response, or throw/reject. |
requestError | function |
Callback invoked if an error happens before a request. Called with the error itself, caused by a preceeding request interceptor rejecting/throwing an error for the request, or a failing in preflight token validation. Should return (or resolve to) new request options, or throw/reject. |
responseError | function |
Callback invoked if an error happens in the response. Called with the error itself, caused by a preceeding response interceptor rejecting/throwing an error for the request, a network error, or an error response from the server. Should return (or resolve to) a new response, or throw/reject. |
The resin-request instance used internally. This should not be necessary in normal usage, but can be useful if you want to make an API request directly, using the same token and hooks as the SDK.
Kind: static property of resin
Summary: Resin request instance
Access: public
Example
resin.request.send({ url: 'http://api.resin.io/ping' });
The resin-pine instance used internally. This should not be necessary in normal usage, but can be useful if you want to directly make pine queries to the api for some resource that isn't directly supported in the SDK.
Kind: static property of resin
Summary: Resin pine instance
Access: public
Example
resin.pine.get({
resource: 'build/$count',
options: {
filter: { belongs_to__application: applicationId }
}
});
The resin-errors module used internally. This is provided primarily for convenience, and to avoid the necessity for separate resin-errors dependencies. You'll want to use this if you need to match on the specific type of error thrown by the SDK.
Kind: static property of resin
Summary: Resin errors module
Access: public
Example
resin.models.device.get(123).catch(function (error) {
if (error.code === resin.errors.ResinDeviceNotFound.code) {
...
} else if (error.code === resin.errors.ResinRequestError.code) {
...
}
});
Kind: static namespace of resin
- .models :
object
- .application :
object
- .tags :
object
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAll([options]) ⇒
Promise
- .set(nameOrId, tagKey, value) ⇒
Promise
- .remove(nameOrId, tagKey) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
- .getAll([options]) ⇒
Promise
- .get(nameOrId, [options]) ⇒
Promise
- .getAppByOwner(appName, owner, [options]) ⇒
Promise
- .has(nameOrId) ⇒
Promise
- .hasAny() ⇒
Promise
.getById(id) ⇒Promise
- .create(name, deviceType, [parentNameOrId]) ⇒
Promise
- .remove(nameOrId) ⇒
Promise
- .restart(nameOrId) ⇒
Promise
- .generateApiKey(nameOrId) ⇒
Promise
- .generateProvisioningKey(nameOrId) ⇒
Promise
- .purge(appId) ⇒
Promise
- .shutdown(appId, [options]) ⇒
Promise
- .reboot(appId, [options]) ⇒
Promise
- .enableDeviceUrls(nameOrId) ⇒
Promise
- .disableDeviceUrls(nameOrId) ⇒
Promise
- .grantSupportAccess(nameOrId, expiryTimestamp) ⇒
Promise
- .revokeSupportAccess(nameOrId) ⇒
Promise
- .tags :
- .device :
object
- .tags :
object
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAllByDevice(uuidOrId, [options]) ⇒
Promise
- .getAll([options]) ⇒
Promise
- .set(uuidOrId, tagKey, value) ⇒
Promise
- .remove(uuidOrId, tagKey) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
- .getDashboardUrl(uuid) ⇒
String
- .getAll([options]) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAllByParentDevice(parentUuidOrId, [options]) ⇒
Promise
- .get(uuidOrId, [options]) ⇒
Promise
- .getByName(name) ⇒
Promise
- .getName(uuidOrId) ⇒
Promise
- .getApplicationName(uuidOrId) ⇒
Promise
- .getApplicationInfo(uuidOrId) ⇒
Promise
- .has(uuidOrId) ⇒
Promise
- .isOnline(uuidOrId) ⇒
Promise
- .getLocalIPAddresses(uuidOrId) ⇒
Promise
- .remove(uuidOrId) ⇒
Promise
- .identify(uuidOrId) ⇒
Promise
- .rename(uuidOrId, newName) ⇒
Promise
- .note(uuidOrId, note) ⇒
Promise
- .setCustomLocation(uuidOrId, location) ⇒
Promise
- .unsetCustomLocation(uuidOrId) ⇒
Promise
- .move(uuidOrId, applicationNameOrId) ⇒
Promise
- .startApplication(uuidOrId) ⇒
Promise
- .stopApplication(uuidOrId) ⇒
Promise
- .restartApplication(uuidOrId) ⇒
Promise
- .reboot(uuidOrId, [options]) ⇒
Promise
- .shutdown(uuidOrId, [options]) ⇒
Promise
- .purge(uuidOrId) ⇒
Promise
- .update(uuidOrId, [options]) ⇒
Promise
- .getDisplayName(deviceTypeSlug) ⇒
Promise
- .getDeviceSlug(deviceTypeName) ⇒
Promise
- .getSupportedDeviceTypes() ⇒
Promise
- .getManifestBySlug(slug) ⇒
Promise
- .getManifestByApplication(nameOrId) ⇒
Promise
- .generateUniqueKey() ⇒
String
- .register(applicationNameOrId, [uuid]) ⇒
Promise
- .generateDeviceKey(uuidOrId) ⇒
Promise
- .hasDeviceUrl(uuidOrId) ⇒
Promise
- .getDeviceUrl(uuidOrId) ⇒
Promise
- .enableDeviceUrl(uuidOrId) ⇒
Promise
- .disableDeviceUrl(uuidOrId) ⇒
Promise
- .enableTcpPing(uuidOrId) ⇒
Promise
- .disableTcpPing(uuidOrId) ⇒
Promise
- .ping(uuidOrId) ⇒
Promise
- .getStatus(device) ⇒
Promise
- .grantSupportAccess(uuidOrId, expiryTimestamp) ⇒
Promise
- .revokeSupportAccess(uuidOrId) ⇒
Promise
- .lastOnline(device) ⇒
String
- .tags :
- .key :
object
- .getAll([options]) ⇒
Promise
- .get(id) ⇒
Promise
- .remove(id) ⇒
Promise
- .create(title, key) ⇒
Promise
- .getAll([options]) ⇒
- .environment-variables :
object
- .device :
object
- .getAll(uuidOrId) ⇒
Promise
- .getAllByApplication(nameOrId) ⇒
Promise
- .create(uuidOrId, envVarName, value) ⇒
Promise
- .update(id, value) ⇒
Promise
- .remove(id) ⇒
Promise
- .getAll(uuidOrId) ⇒
- .getAllByApplication(applicationNameOrId) ⇒
Promise
- .create(applicationNameOrId, envVarName, value) ⇒
Promise
- .update(id, value) ⇒
Promise
- .remove(id) ⇒
Promise
- .isSystemVariable(variable) ⇒
Boolean
- .device :
- .os :
object
- .getDownloadSize(deviceType, [version]) ⇒
Promise
- .getSupportedVersions(deviceType) ⇒
Promise
- .getMaxSatisfyingVersion(deviceType, versionOrRange) ⇒
Promise
- .getLastModified(deviceType, [version]) ⇒
Promise
- .download(deviceType, [version]) ⇒
Promise
- .getConfig(nameOrId, [options]) ⇒
Promise
- .getDownloadSize(deviceType, [version]) ⇒
- .config :
object
- .getAll() ⇒
Promise
- .getDeviceTypes() ⇒
Promise
- .getDeviceOptions(deviceType) ⇒
Promise
- .getAll() ⇒
- .build :
object
- .get(id, [options]) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .get(id, [options]) ⇒
- .billing :
object
- .getAccount() ⇒
Promise
- .getPlan() ⇒
Promise
- .getBillingInfo() ⇒
Promise
- .updateBillingInfo() ⇒
Promise
- .getInvoices() ⇒
Promise
- .downloadInvoice() ⇒
Promise
- .getAccount() ⇒
- .application :
Kind: static namespace of models
- .application :
object
- .tags :
object
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAll([options]) ⇒
Promise
- .set(nameOrId, tagKey, value) ⇒
Promise
- .remove(nameOrId, tagKey) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
- .getAll([options]) ⇒
Promise
- .get(nameOrId, [options]) ⇒
Promise
- .getAppByOwner(appName, owner, [options]) ⇒
Promise
- .has(nameOrId) ⇒
Promise
- .hasAny() ⇒
Promise
.getById(id) ⇒Promise
- .create(name, deviceType, [parentNameOrId]) ⇒
Promise
- .remove(nameOrId) ⇒
Promise
- .restart(nameOrId) ⇒
Promise
- .generateApiKey(nameOrId) ⇒
Promise
- .generateProvisioningKey(nameOrId) ⇒
Promise
- .purge(appId) ⇒
Promise
- .shutdown(appId, [options]) ⇒
Promise
- .reboot(appId, [options]) ⇒
Promise
- .enableDeviceUrls(nameOrId) ⇒
Promise
- .disableDeviceUrls(nameOrId) ⇒
Promise
- .grantSupportAccess(nameOrId, expiryTimestamp) ⇒
Promise
- .revokeSupportAccess(nameOrId) ⇒
Promise
- .tags :
Kind: static namespace of application
- .tags :
object
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAll([options]) ⇒
Promise
- .set(nameOrId, tagKey, value) ⇒
Promise
- .remove(nameOrId, tagKey) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
Kind: static method of tags
Summary: Get all application tags for an application
Access: public
Fulfil: Object[]
- application tags
Param | Type | Default | Description |
---|---|---|---|
nameOrId | String | Number |
application name (string) or id (number) | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.application.tags.getAllByApplication('MyApp').then(function(tags) {
console.log(tags);
});
Example
resin.models.application.tags.getAllByApplication(999999).then(function(tags) {
console.log(tags);
});
Example
resin.models.application.tags.getAllByApplication('MyApp', function(error, tags) {
if (error) throw error;
console.log(tags)
});
Kind: static method of tags
Summary: Get all application tags
Access: public
Fulfil: Object[]
- application tags
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.application.tags.getAll().then(function(tags) {
console.log(tags);
});
Example
resin.models.application.tags.getAll(function(error, tags) {
if (error) throw error;
console.log(tags)
});
Kind: static method of tags
Summary: Set an application tag
Access: public
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
tagKey | String |
tag key |
value | String | undefined |
tag value |
Example
resin.models.application.tags.set('7cf02a6', 'EDITOR', 'vim');
Example
resin.models.application.tags.set(123, 'EDITOR', 'vim');
Example
resin.models.application.tags.set('7cf02a6', 'EDITOR', 'vim', function(error) {
if (error) throw error;
});
Kind: static method of tags
Summary: Remove an application tag
Access: public
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
tagKey | String |
tag key |
Example
resin.models.application.tags.remove('7cf02a6', 'EDITOR');
Example
resin.models.application.tags.remove('7cf02a6', 'EDITOR', function(error) {
if (error) throw error;
});
Kind: static method of application
Summary: Get all applications
Access: public
Fulfil: Object[]
- applications
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.application.getAll().then(function(applications) {
console.log(applications);
});
Example
resin.models.application.getAll(function(error, applications) {
if (error) throw error;
console.log(applications);
});
Kind: static method of application
Summary: Get a single application
Access: public
Fulfil: Object
- application
Param | Type | Default | Description |
---|---|---|---|
nameOrId | String | Number |
application name (string) or id (number) | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.application.get('MyApp').then(function(application) {
console.log(application);
});
Example
resin.models.application.get(123).then(function(application) {
console.log(application);
});
Example
resin.models.application.get('MyApp', function(error, application) {
if (error) throw error;
console.log(application);
});
Kind: static method of application
Summary: Get a single application using the appname and owner's username
Access: public
Fulfil: Object
- application
Param | Type | Default | Description |
---|---|---|---|
appName | String |
application name | |
owner | String |
The owner's username | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.application.getAppByOwner('MyApp', 'MyUser').then(function(application) {
console.log(application);
});
Kind: static method of application
Summary: Check if an application exists
Access: public
Fulfil: Boolean
- has application
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.application.has('MyApp').then(function(hasApp) {
console.log(hasApp);
});
Example
resin.models.application.has(123).then(function(hasApp) {
console.log(hasApp);
});
Example
resin.models.application.has('MyApp', function(error, hasApp) {
if (error) throw error;
console.log(hasApp);
});
Kind: static method of application
Summary: Check if the user has any applications
Access: public
Fulfil: Boolean
- has any applications
Example
resin.models.application.hasAny().then(function(hasAny) {
console.log('Has any?', hasAny);
});
Example
resin.models.application.hasAny(function(error, hasAny) {
if (error) throw error;
console.log('Has any?', hasAny);
});
Deprecated
Kind: static method of application
Summary: Get a single application by id
Access: public
Fulfil: Object
- application
Param | Type | Description |
---|---|---|
id | Number | String |
application id |
Example
resin.models.application.getById(89).then(function(application) {
console.log(application);
});
Example
resin.models.application.getById(89, function(error, application) {
if (error) throw error;
console.log(application);
});
Kind: static method of application
Summary: Create an application
Access: public
Fulfil: Object
- application
Param | Type | Description |
---|---|---|
name | String |
application name |
deviceType | String |
device type slug |
[parentNameOrId] | Number | String |
parent application name or id |
Example
resin.models.application.create('My App', 'raspberry-pi').then(function(application) {
console.log(application);
});
Example
resin.models.application.create('My App', 'raspberry-pi', 'ParentApp').then(function(application) {
console.log(application);
});
Example
resin.models.application.create('My App', 'raspberry-pi', function(error, application) {
if (error) throw error;
console.log(application);
});
Kind: static method of application
Summary: Remove application
Access: public
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.application.remove('MyApp');
Example
resin.models.application.remove(123);
Example
resin.models.application.remove('MyApp', function(error) {
if (error) throw error;
});
Kind: static method of application
Summary: Restart application
Access: public
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.application.restart('MyApp');
Example
resin.models.application.restart(123);
Example
resin.models.application.restart('MyApp', function(error) {
if (error) throw error;
});
Generally you shouldn't use this method: if you're provisioning a recent ResinOS version (2.4.0+) then generateProvisioningKey should work just as well, but be more secure.
Kind: static method of application
Summary: Generate an API key for a specific application
Access: public
Fulfil: String
- api key
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.application.generateApiKey('MyApp').then(function(apiKey) {
console.log(apiKey);
});
Example
resin.models.application.generateApiKey(123).then(function(apiKey) {
console.log(apiKey);
});
Example
resin.models.application.generateApiKey('MyApp', function(error, apiKey) {
if (error) throw error;
console.log(apiKey);
});
Kind: static method of application
Summary: Generate a device provisioning key for a specific application
Access: public
Fulfil: String
- device provisioning key
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.application.generateProvisioningKey('MyApp').then(function(key) {
console.log(key);
});
Example
resin.models.application.generateProvisioningKey(123).then(function(key) {
console.log(key);
});
Example
resin.models.application.generateProvisioningKey('MyApp', function(error, key) {
if (error) throw error;
console.log(key);
});
Kind: static method of application
Summary: Purge devices by application id
Access: public
Param | Type | Description |
---|---|---|
appId | Number |
application id |
Example
resin.models.application.purge(123);
Example
resin.models.application.purge(123, function(error) {
if (error) throw error;
});
Kind: static method of application
Summary: Shutdown devices by application id
Access: public
Param | Type | Default | Description |
---|---|---|---|
appId | Number |
application id | |
[options] | Object |
options | |
[options.force] | Boolean |
false |
override update lock |
Example
resin.models.application.shutdown(123);
Example
resin.models.application.shutdown(123, function(error) {
if (error) throw error;
});
Kind: static method of application
Summary: Reboot devices by application id
Access: public
Param | Type | Default | Description |
---|---|---|---|
appId | Number |
application id | |
[options] | Object |
options | |
[options.force] | Boolean |
false |
override update lock |
Example
resin.models.application.reboot(123);
Example
resin.models.application.reboot(123, function(error) {
if (error) throw error;
});
Kind: static method of application
Summary: Enable device urls for all devices that belong to an application
Access: public
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.application.enableDeviceUrls('MyApp');
Example
resin.models.application.enableDeviceUrls(123);
Example
resin.models.device.enableDeviceUrls('MyApp', function(error) {
if (error) throw error;
});
Kind: static method of application
Summary: Disable device urls for all devices that belong to an application
Access: public
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.application.disableDeviceUrls('MyApp');
Example
resin.models.application.disableDeviceUrls(123);
Example
resin.models.device.disableDeviceUrls('MyApp', function(error) {
if (error) throw error;
});
Kind: static method of application
Summary: Grant support access to an application until a specified time
Access: public
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
expiryTimestamp | Number |
a timestamp in ms for when the support access will expire |
Example
resin.models.application.grantSupportAccess('MyApp', Date.now() + 3600 * 1000);
Example
resin.models.application.grantSupportAccess(123, Date.now() + 3600 * 1000);
Example
resin.models.application.grantSupportAccess('MyApp', Date.now() + 3600 * 1000, function(error) {
if (error) throw error;
});
Kind: static method of application
Summary: Revoke support access to an application
Access: public
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.application.revokeSupportAccess('MyApp');
Example
resin.models.application.revokeSupportAccess(123);
Example
resin.models.application.revokeSupportAccess('MyApp', function(error) {
if (error) throw error;
});
Kind: static namespace of models
- .device :
object
- .tags :
object
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAllByDevice(uuidOrId, [options]) ⇒
Promise
- .getAll([options]) ⇒
Promise
- .set(uuidOrId, tagKey, value) ⇒
Promise
- .remove(uuidOrId, tagKey) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
- .getDashboardUrl(uuid) ⇒
String
- .getAll([options]) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAllByParentDevice(parentUuidOrId, [options]) ⇒
Promise
- .get(uuidOrId, [options]) ⇒
Promise
- .getByName(name) ⇒
Promise
- .getName(uuidOrId) ⇒
Promise
- .getApplicationName(uuidOrId) ⇒
Promise
- .getApplicationInfo(uuidOrId) ⇒
Promise
- .has(uuidOrId) ⇒
Promise
- .isOnline(uuidOrId) ⇒
Promise
- .getLocalIPAddresses(uuidOrId) ⇒
Promise
- .remove(uuidOrId) ⇒
Promise
- .identify(uuidOrId) ⇒
Promise
- .rename(uuidOrId, newName) ⇒
Promise
- .note(uuidOrId, note) ⇒
Promise
- .setCustomLocation(uuidOrId, location) ⇒
Promise
- .unsetCustomLocation(uuidOrId) ⇒
Promise
- .move(uuidOrId, applicationNameOrId) ⇒
Promise
- .startApplication(uuidOrId) ⇒
Promise
- .stopApplication(uuidOrId) ⇒
Promise
- .restartApplication(uuidOrId) ⇒
Promise
- .reboot(uuidOrId, [options]) ⇒
Promise
- .shutdown(uuidOrId, [options]) ⇒
Promise
- .purge(uuidOrId) ⇒
Promise
- .update(uuidOrId, [options]) ⇒
Promise
- .getDisplayName(deviceTypeSlug) ⇒
Promise
- .getDeviceSlug(deviceTypeName) ⇒
Promise
- .getSupportedDeviceTypes() ⇒
Promise
- .getManifestBySlug(slug) ⇒
Promise
- .getManifestByApplication(nameOrId) ⇒
Promise
- .generateUniqueKey() ⇒
String
- .register(applicationNameOrId, [uuid]) ⇒
Promise
- .generateDeviceKey(uuidOrId) ⇒
Promise
- .hasDeviceUrl(uuidOrId) ⇒
Promise
- .getDeviceUrl(uuidOrId) ⇒
Promise
- .enableDeviceUrl(uuidOrId) ⇒
Promise
- .disableDeviceUrl(uuidOrId) ⇒
Promise
- .enableTcpPing(uuidOrId) ⇒
Promise
- .disableTcpPing(uuidOrId) ⇒
Promise
- .ping(uuidOrId) ⇒
Promise
- .getStatus(device) ⇒
Promise
- .grantSupportAccess(uuidOrId, expiryTimestamp) ⇒
Promise
- .revokeSupportAccess(uuidOrId) ⇒
Promise
- .lastOnline(device) ⇒
String
- .tags :
Kind: static namespace of device
- .tags :
object
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .getAllByDevice(uuidOrId, [options]) ⇒
Promise
- .getAll([options]) ⇒
Promise
- .set(uuidOrId, tagKey, value) ⇒
Promise
- .remove(uuidOrId, tagKey) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
Kind: static method of tags
Summary: Get all device tags for an application
Access: public
Fulfil: Object[]
- device tags
Param | Type | Default | Description |
---|---|---|---|
nameOrId | String | Number |
application name (string) or id (number) | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.device.tags.getAllByApplication('MyApp').then(function(tags) {
console.log(tags);
});
Example
resin.models.device.tags.getAllByApplication(999999).then(function(tags) {
console.log(tags);
});
Example
resin.models.device.tags.getAllByApplication('MyApp', function(error, tags) {
if (error) throw error;
console.log(tags)
});
Kind: static method of tags
Summary: Get all device tags for a device
Access: public
Fulfil: Object[]
- device tags
Param | Type | Default | Description |
---|---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.device.tags.getAllByDevice('7cf02a6').then(function(tags) {
console.log(tags);
});
Example
resin.models.device.tags.getAllByDevice(123).then(function(tags) {
console.log(tags);
});
Example
resin.models.device.tags.getAllByDevice('7cf02a6', function(error, tags) {
if (error) throw error;
console.log(tags)
});
Kind: static method of tags
Summary: Get all device tags
Access: public
Fulfil: Object[]
- device tags
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.device.tags.getAll().then(function(tags) {
console.log(tags);
});
Example
resin.models.device.tags.getAll(function(error, tags) {
if (error) throw error;
console.log(tags)
});
Kind: static method of tags
Summary: Set a device tag
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
tagKey | String |
tag key |
value | String | undefined |
tag value |
Example
resin.models.device.tags.set('7cf02a6', 'EDITOR', 'vim');
Example
resin.models.device.tags.set(123, 'EDITOR', 'vim');
Example
resin.models.device.tags.set('7cf02a6', 'EDITOR', 'vim', function(error) {
if (error) throw error;
});
Kind: static method of tags
Summary: Remove a device tag
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
tagKey | String |
tag key |
Example
resin.models.device.tags.remove('7cf02a6', 'EDITOR');
Example
resin.models.device.tags.remove('7cf02a6', 'EDITOR', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Get Dashboard URL for a specific device
Returns: String
- - Dashboard URL for the specific device
Throws:
- Exception if the uuid is empty
Param | Type | Description |
---|---|---|
uuid | String |
Device uuid |
Example
dashboardDeviceUrl = resin.models.device.getDashboardUrl('a44b544b8cc24d11b036c659dfeaccd8')
Kind: static method of device
Summary: Get all devices
Access: public
Fulfil: Object[]
- devices
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.device.getAll().then(function(devices) {
console.log(devices);
});
Example
resin.models.device.getAll(function(error, devices) {
if (error) throw error;
console.log(devices);
});
Kind: static method of device
Summary: Get all devices by application
Access: public
Fulfil: Object[]
- devices
Param | Type | Default | Description |
---|---|---|---|
nameOrId | String | Number |
application name (string) or id (number) | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.device.getAllByApplication('MyApp').then(function(devices) {
console.log(devices);
});
Example
resin.models.device.getAllByApplication(123).then(function(devices) {
console.log(devices);
});
Example
resin.models.device.getAllByApplication('MyApp', function(error, devices) {
if (error) throw error;
console.log(devices);
});
Kind: static method of device
Summary: Get all devices by parent device
Access: public
Fulfil: Object[]
- devices
Param | Type | Default | Description |
---|---|---|---|
parentUuidOrId | String | Number |
parent device uuid (string) or id (number) | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.device.getAllByParentDevice('7cf02a6').then(function(devices) {
console.log(devices);
});
Example
resin.models.device.getAllByParentDevice(123).then(function(devices) {
console.log(devices);
});
Example
resin.models.device.getAllByParentDevice('7cf02a6', function(error, devices) {
if (error) throw error;
console.log(devices);
});
Kind: static method of device
Summary: Get a single device
Access: public
Fulfil: Object
- device
Param | Type | Default | Description |
---|---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.device.get('7cf02a6').then(function(device) {
console.log(device);
})
Example
resin.models.device.get(123).then(function(device) {
console.log(device);
})
Example
resin.models.device.get('7cf02a6', function(error, device) {
if (error) throw error;
console.log(device);
});
Kind: static method of device
Summary: Get devices by name
Access: public
Fulfil: Object[]
- devices
Param | Type | Description |
---|---|---|
name | String |
device name |
Example
resin.models.device.getByName('MyDevice').then(function(devices) {
console.log(devices);
});
Example
resin.models.device.getByName('MyDevice', function(error, devices) {
if (error) throw error;
console.log(devices);
});
Kind: static method of device
Summary: Get the name of a device
Access: public
Fulfil: String
- device name
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.getName('7cf02a6').then(function(deviceName) {
console.log(deviceName);
});
Example
resin.models.device.getName(123).then(function(deviceName) {
console.log(deviceName);
});
Example
resin.models.device.getName('7cf02a6', function(error, deviceName) {
if (error) throw error;
console.log(deviceName);
});
Kind: static method of device
Summary: Get application name
Access: public
Fulfil: String
- application name
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.getApplicationName('7cf02a6').then(function(applicationName) {
console.log(applicationName);
});
Example
resin.models.device.getApplicationName(123).then(function(applicationName) {
console.log(applicationName);
});
Example
resin.models.device.getApplicationName('7cf02a6', function(error, applicationName) {
if (error) throw error;
console.log(applicationName);
});
Kind: static method of device
Summary: Get application container information
Access: public
Fulfil: Object
- application info
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.getApplicationInfo('7cf02a6').then(function(appInfo) {
console.log(appInfo);
});
Example
resin.models.device.getApplicationInfo(123).then(function(appInfo) {
console.log(appInfo);
});
Example
resin.models.device.getApplicationInfo('7cf02a6', function(error, appInfo) {
if (error) throw error;
console.log(appInfo);
});
Kind: static method of device
Summary: Check if a device exists
Access: public
Fulfil: Boolean
- has device
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.has('7cf02a6').then(function(hasDevice) {
console.log(hasDevice);
});
Example
resin.models.device.has(123).then(function(hasDevice) {
console.log(hasDevice);
});
Example
resin.models.device.has('7cf02a6', function(error, hasDevice) {
if (error) throw error;
console.log(hasDevice);
});
Kind: static method of device
Summary: Check if a device is online
Access: public
Fulfil: Boolean
- is device online
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.isOnline('7cf02a6').then(function(isOnline) {
console.log('Is device online?', isOnline);
});
Example
resin.models.device.isOnline(123).then(function(isOnline) {
console.log('Is device online?', isOnline);
});
Example
resin.models.device.isOnline('7cf02a6', function(error, isOnline) {
if (error) throw error;
console.log('Is device online?', isOnline);
});
Kind: static method of device
Summary: Get the local IP addresses of a device
Access: public
Fulfil: String[]
- local ip addresses
Reject: Error
Will reject if the device is offline
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.getLocalIPAddresses('7cf02a6').then(function(localIPAddresses) {
localIPAddresses.forEach(function(localIP) {
console.log(localIP);
});
});
Example
resin.models.device.getLocalIPAddresses(123).then(function(localIPAddresses) {
localIPAddresses.forEach(function(localIP) {
console.log(localIP);
});
});
Example
resin.models.device.getLocalIPAddresses('7cf02a6', function(error, localIPAddresses) {
if (error) throw error;
localIPAddresses.forEach(function(localIP) {
console.log(localIP);
});
});
Kind: static method of device
Summary: Remove device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.remove('7cf02a6');
Example
resin.models.device.remove(123);
Example
resin.models.device.remove('7cf02a6', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Identify device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.identify('7cf02a6');
Example
resin.models.device.identify(123);
Example
resin.models.device.identify('7cf02a6', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Rename device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
newName | String |
the device new name |
Example
resin.models.device.rename('7cf02a6', 'NewName');
Example
resin.models.device.rename(123, 'NewName');
Example
resin.models.device.rename('7cf02a6', 'NewName', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Note a device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
note | String |
the note |
Example
resin.models.device.note('7cf02a6', 'My useful note');
Example
resin.models.device.note(123, 'My useful note');
Example
resin.models.device.note('7cf02a6', 'My useful note', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Set a custom location for a device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
location | Object |
the location ({ latitude: 123, longitude: 456 }) |
Example
resin.models.device.setCustomLocation('7cf02a6', { latitude: 123, longitude: 456 });
Example
resin.models.device.setCustomLocation(123, { latitude: 123, longitude: 456 });
Example
resin.models.device.setCustomLocation('7cf02a6', { latitude: 123, longitude: 456 }, function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Clear the custom location of a device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.unsetCustomLocation('7cf02a6');
Example
resin.models.device.unsetCustomLocation(123);
Example
resin.models.device.unsetLocation('7cf02a6', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Move a device to another application
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
applicationNameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.device.move('7cf02a6', 'MyApp');
Example
resin.models.device.move(123, 'MyApp');
Example
resin.models.device.move(123, 456);
Example
resin.models.device.move('7cf02a6', 'MyApp', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Start application on device
Access: public
Fulfil: String
- application container id
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.startApplication('7cf02a6').then(function(containerId) {
console.log(containerId);
});
Example
resin.models.device.startApplication(123).then(function(containerId) {
console.log(containerId);
});
Example
resin.models.device.startApplication('7cf02a6', function(error, containerId) {
if (error) throw error;
console.log(containerId);
});
Kind: static method of device
Summary: Stop application on device
Access: public
Fulfil: String
- application container id
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.stopApplication('7cf02a6').then(function(containerId) {
console.log(containerId);
});
Example
resin.models.device.stopApplication(123).then(function(containerId) {
console.log(containerId);
});
Example
resin.models.device.stopApplication('7cf02a6', function(error, containerId) {
if (error) throw error;
console.log(containerId);
});
This function restarts the Docker container running the application on the device, but doesn't reboot the device itself.
Kind: static method of device
Summary: Restart application on device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.restartApplication('7cf02a6');
Example
resin.models.device.restartApplication(123);
Example
resin.models.device.restartApplication('7cf02a6', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Reboot device
Access: public
Param | Type | Default | Description |
---|---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) | |
[options] | Object |
options | |
[options.force] | Boolean |
false |
override update lock |
Example
resin.models.device.reboot('7cf02a6');
Example
resin.models.device.reboot(123);
Example
resin.models.device.reboot('7cf02a6', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Shutdown device
Access: public
Param | Type | Default | Description |
---|---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) | |
[options] | Object |
options | |
[options.force] | Boolean |
false |
override update lock |
Example
resin.models.device.shutdown('7cf02a6');
Example
resin.models.device.shutdown(123);
Example
resin.models.device.shutdown('7cf02a6', function(error) {
if (error) throw error;
});
This function clears the user application's /data
directory.
Kind: static method of device
Summary: Purge device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.purge('7cf02a6');
Example
resin.models.device.purge(123);
Example
resin.models.device.purge('7cf02a6', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Trigger an update check on the supervisor
Access: public
Param | Type | Default | Description |
---|---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) | |
[options] | Object |
options | |
[options.force] | Boolean |
false |
override update lock |
Example
resin.models.device.update('7cf02a6', {
force: true
});
Example
resin.models.device.update(123, {
force: true
});
Example
resin.models.device.update('7cf02a6', {
force: true
}, function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Get display name for a device
Access: public
Fulfil: String
- device display name
See: module:resin.models.device.getSupportedDeviceTypes for a list of supported devices
Param | Type | Description |
---|---|---|
deviceTypeSlug | String |
device type slug |
Example
resin.models.device.getDisplayName('raspberry-pi').then(function(deviceTypeName) {
console.log(deviceTypeName);
// Raspberry Pi
});
Example
resin.models.device.getDisplayName('raspberry-pi', function(error, deviceTypeName) {
if (error) throw error;
console.log(deviceTypeName);
// Raspberry Pi
});
Kind: static method of device
Summary: Get device slug
Access: public
Fulfil: String
- device slug name
See: module:resin.models.device.getSupportedDeviceTypes for a list of supported devices
Param | Type | Description |
---|---|---|
deviceTypeName | String |
device type name |
Example
resin.models.device.getDeviceSlug('Raspberry Pi').then(function(deviceTypeSlug) {
console.log(deviceTypeSlug);
// raspberry-pi
});
Example
resin.models.device.getDeviceSlug('Raspberry Pi', function(error, deviceTypeSlug) {
if (error) throw error;
console.log(deviceTypeSlug);
// raspberry-pi
});
Kind: static method of device
Summary: Get supported device types
Access: public
Fulfil: String[]
- supported device types
Example
resin.models.device.getSupportedDeviceTypes().then(function(supportedDeviceTypes) {
supportedDeviceTypes.forEach(function(supportedDeviceType) {
console.log('Resin supports:', supportedDeviceType);
});
});
Example
resin.models.device.getSupportedDeviceTypes(function(error, supportedDeviceTypes) {
if (error) throw error;
supportedDeviceTypes.forEach(function(supportedDeviceType) {
console.log('Resin supports:', supportedDeviceType);
});
});
Kind: static method of device
Summary: Get a device manifest by slug
Access: public
Fulfil: Object
- device manifest
Param | Type | Description |
---|---|---|
slug | String |
device slug |
Example
resin.models.device.getManifestBySlug('raspberry-pi').then(function(manifest) {
console.log(manifest);
});
Example
resin.models.device.getManifestBySlug('raspberry-pi', function(error, manifest) {
if (error) throw error;
console.log(manifest);
});
Kind: static method of device
Summary: Get a device manifest by application name
Access: public
Fulfil: Object
- device manifest
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.device.getManifestByApplication('MyApp').then(function(manifest) {
console.log(manifest);
});
Example
resin.models.device.getManifestByApplication(123).then(function(manifest) {
console.log(manifest);
});
Example
resin.models.device.getManifestByApplication('MyApp', function(error, manifest) {
if (error) throw error;
console.log(manifest);
});
Kind: static method of device
Summary: Generate a random key, useful for both uuid and api key.
Returns: String
- A generated key
Access: public
Example
randomKey = resin.models.device.generateUniqueKey();
// randomKey is a randomly generated key that can be used as either a uuid or an api key
console.log(randomKey);
Kind: static method of device
Summary: Register a new device with a Resin.io application.
Access: public
Fulfil: Object
Device registration info ({ id: "...", uuid: "...", api_key: "..." })
Param | Type | Description |
---|---|---|
applicationNameOrId | String | Number |
application name (string) or id (number) |
[uuid] | String |
device uuid |
Example
var uuid = resin.models.device.generateUniqueKey();
resin.models.device.register('MyApp', uuid).then(function(registrationInfo) {
console.log(registrationInfo);
});
Example
var uuid = resin.models.device.generateUniqueKey();
resin.models.device.register(123, uuid).then(function(registrationInfo) {
console.log(registrationInfo);
});
Example
var uuid = resin.models.device.generateUniqueKey();
resin.models.device.register('MyApp', uuid, function(error, registrationInfo) {
if (error) throw error;
console.log(registrationInfo);
});
Kind: static method of device
Summary: Generate a device key
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.generateDeviceKey('7cf02a6').then(function(deviceApiKey) {
console.log(deviceApiKey);
});
Example
resin.models.device.generateDeviceKey(123).then(function(deviceApiKey) {
console.log(deviceApiKey);
});
Example
resin.models.device.generateDeviceKey('7cf02a6', function(error, deviceApiKey) {
if (error) throw error;
console.log(deviceApiKey);
});
Kind: static method of device
Summary: Check if a device is web accessible with device utls
Access: public
Fulfil: Boolean
- has device url
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.hasDeviceUrl('7cf02a6').then(function(hasDeviceUrl) {
if (hasDeviceUrl) {
console.log('The device has device URL enabled');
}
});
Example
resin.models.device.hasDeviceUrl(123).then(function(hasDeviceUrl) {
if (hasDeviceUrl) {
console.log('The device has device URL enabled');
}
});
Example
resin.models.device.hasDeviceUrl('7cf02a6', function(error, hasDeviceUrl) {
if (error) throw error;
if (hasDeviceUrl) {
console.log('The device has device URL enabled');
}
});
Kind: static method of device
Summary: Get a device url
Access: public
Fulfil: String
- device url
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.getDeviceUrl('7cf02a6').then(function(url) {
console.log(url);
});
Example
resin.models.device.getDeviceUrl(123).then(function(url) {
console.log(url);
});
Example
resin.models.device.getDeviceUrl('7cf02a6', function(error, url) {
if (error) throw error;
console.log(url);
});
Kind: static method of device
Summary: Enable device url for a device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.enableDeviceUrl('7cf02a6');
Example
resin.models.device.enableDeviceUrl(123);
Example
resin.models.device.enableDeviceUrl('7cf02a6', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Disable device url for a device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.disableDeviceUrl('7cf02a6');
Example
resin.models.device.disableDeviceUrl(123);
Example
resin.models.device.disableDeviceUrl('7cf02a6', function(error) {
if (error) throw error;
});
When the device's connection to the Resin VPN is down, by default the device performs a TCP ping heartbeat to check for connectivity. This is enabled by default.
Kind: static method of device
Summary: Enable TCP ping for a device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.enableTcpPing('7cf02a6');
Example
resin.models.device.enableTcpPing(123);
Example
resin.models.device.enableTcpPing('7cf02a6', function(error) {
if (error) throw error;
});
When the device's connection to the Resin VPN is down, by default the device performs a TCP ping heartbeat to check for connectivity.
Kind: static method of device
Summary: Disable TCP ping for a device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.disableTcpPing('7cf02a6');
Example
resin.models.device.disableTcpPing(123);
Example
resin.models.device.disableTcpPing('7cf02a6', function(error) {
if (error) throw error;
});
This is useful to signal that the supervisor is alive and responding.
Kind: static method of device
Summary: Ping a device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.ping('7cf02a6');
Example
resin.models.device.ping(123);
Example
resin.models.device.ping('7cf02a6', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Get the status of a device
Access: public
Fulfil: String
- device status
Param | Type | Description |
---|---|---|
device | Object |
A device object |
Example
resin.models.device.getStatus(device).then(function(status) {
console.log(status);
});
Example
resin.models.device.getStatus(device, function(error, status) {
if (error) throw error;
console.log(status);
});
Kind: static method of device
Summary: Grant support access to a device until a specified time
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
expiryTimestamp | Number |
a timestamp in ms for when the support access will expire |
Example
resin.models.device.grantSupportAccess('7cf02a6', Date.now() + 3600 * 1000);
Example
resin.models.device.grantSupportAccess(123, Date.now() + 3600 * 1000);
Example
resin.models.device.grantSupportAccess('7cf02a6', Date.now() + 3600 * 1000, function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Revoke support access to a device
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.device.revokeSupportAccess('7cf02a6');
Example
resin.models.device.revokeSupportAccess(123);
Example
resin.models.device.revokeSupportAccess('7cf02a6', function(error) {
if (error) throw error;
});
If the device has never been online this method returns the string Connecting...
.
Kind: static method of device
Summary: Get a string showing when a device was last set as online
Access: public
Param | Type | Description |
---|---|---|
device | Object |
A device object |
Example
resin.models.device.get('7cf02a6').then(function(device) {
resin.models.device.lastOnline(device);
})
Kind: static namespace of models
- .key :
object
- .getAll([options]) ⇒
Promise
- .get(id) ⇒
Promise
- .remove(id) ⇒
Promise
- .create(title, key) ⇒
Promise
- .getAll([options]) ⇒
Kind: static method of key
Summary: Get all ssh keys
Access: public
Fulfil: Object[]
- ssh keys
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.key.getAll().then(function(keys) {
console.log(keys);
});
Example
resin.models.key.getAll(function(error, keys) {
if (error) throw error;
console.log(keys);
});
Kind: static method of key
Summary: Get a single ssh key
Access: public
Fulfil: Object
- ssh key
Param | Type | Description |
---|---|---|
id | String | Number |
key id |
Example
resin.models.key.get(51).then(function(key) {
console.log(key);
});
Example
resin.models.key.get(51, function(error, key) {
if (error) throw error;
console.log(key);
});
Kind: static method of key
Summary: Remove ssh key
Access: public
Param | Type | Description |
---|---|---|
id | String | Number |
key id |
Example
resin.models.key.remove(51);
Example
resin.models.key.remove(51, function(error) {
if (error) throw error;
});
Kind: static method of key
Summary: Create a ssh key
Access: public
Fulfil: Object
- ssh key
Param | Type | Description |
---|---|---|
title | String |
key title |
key | String |
the public ssh key |
Example
resin.models.key.create('Main', 'ssh-rsa AAAAB....').then(function(key) {
console.log(key);
});
Example
resin.models.key.create('Main', 'ssh-rsa AAAAB....', function(error, key) {
if (error) throw error;
console.log(key);
});
Kind: static namespace of models
- .environment-variables :
object
- .device :
object
- .getAll(uuidOrId) ⇒
Promise
- .getAllByApplication(nameOrId) ⇒
Promise
- .create(uuidOrId, envVarName, value) ⇒
Promise
- .update(id, value) ⇒
Promise
- .remove(id) ⇒
Promise
- .getAll(uuidOrId) ⇒
- .getAllByApplication(applicationNameOrId) ⇒
Promise
- .create(applicationNameOrId, envVarName, value) ⇒
Promise
- .update(id, value) ⇒
Promise
- .remove(id) ⇒
Promise
- .isSystemVariable(variable) ⇒
Boolean
- .device :
Kind: static namespace of environment-variables
- .device :
object
- .getAll(uuidOrId) ⇒
Promise
- .getAllByApplication(nameOrId) ⇒
Promise
- .create(uuidOrId, envVarName, value) ⇒
Promise
- .update(id, value) ⇒
Promise
- .remove(id) ⇒
Promise
- .getAll(uuidOrId) ⇒
Kind: static method of device
Summary: Get all device environment variables
Access: public
Fulfil: Object[]
- device environment variables
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.models.environmentVariables.device.getAll('7cf02a6').then(function(environmentVariables) {
console.log(environmentVariables);
});
Example
resin.models.environmentVariables.device.getAll(123).then(function(environmentVariables) {
console.log(environmentVariables);
});
Example
resin.models.environmentVariables.device.getAll('7cf02a6', function(error, environmentVariables) {
if (error) throw error;
console.log(environmentVariables)
});
Kind: static method of device
Summary: Get all device environment variables for an application
Access: public
Fulfil: Object[]
- device environment variables
Param | Type | Description |
---|---|---|
nameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.environmentVariables.device.getAllByApplication('MyApp').then(function(environmentVariables) {
console.log(environmentVariables);
});
Example
resin.models.environmentVariables.device.getAllByApplication(999999).then(function(environmentVariables) {
console.log(environmentVariables);
});
Example
resin.models.environmentVariables.device.getAllByApplication('MyApp', function(error, environmentVariables) {
if (error) throw error;
console.log(environmentVariables)
});
Kind: static method of device
Summary: Create a device environment variable
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
envVarName | String |
environment variable name |
value | String |
environment variable value |
Example
resin.models.environmentVariables.device.create('7cf02a6', 'EDITOR', 'vim');
Example
resin.models.environmentVariables.device.create(123, 'EDITOR', 'vim');
Example
resin.models.environmentVariables.device.create('7cf02a6', 'EDITOR', 'vim', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Update a device environment variable
Access: public
Param | Type | Description |
---|---|---|
id | String | Number |
environment variable id |
value | String |
environment variable value |
Example
resin.models.environmentVariables.device.update(2, 'emacs');
Example
resin.models.environmentVariables.device.update(2, 'emacs', function(error) {
if (error) throw error;
});
Kind: static method of device
Summary: Remove a device environment variable
Access: public
Param | Type | Description |
---|---|---|
id | String | Number |
environment variable id |
Example
resin.models.environmentVariables.device.remove(2);
Example
resin.models.environmentVariables.device.remove(2, function(error) {
if (error) throw error;
});
Kind: static method of environment-variables
Summary: Get all environment variables by application
Access: public
Fulfil: Object[]
- environment variables
Param | Type | Description |
---|---|---|
applicationNameOrId | String | Number |
application name (string) or id (number) |
Example
resin.models.environmentVariables.getAllByApplication('MyApp').then(function(environmentVariables) {
console.log(environmentVariables);
});
Example
resin.models.environmentVariables.getAllByApplication(123).then(function(environmentVariables) {
console.log(environmentVariables);
});
Example
resin.models.environmentVariables.getAllByApplication('MyApp', function(error, environmentVariables) {
if (error) throw error;
console.log(environmentVariables);
});
Kind: static method of environment-variables
Summary: Create an environment variable for an application
Access: public
Param | Type | Description |
---|---|---|
applicationNameOrId | String | Number |
application name (string) or id (number) |
envVarName | String |
environment variable name |
value | String |
environment variable value |
Example
resin.models.environmentVariables.create('MyApp', 'EDITOR', 'vim');
Example
resin.models.environmentVariables.create(123, 'EDITOR', 'vim');
Example
resin.models.environmentVariables.create('MyApp', 'EDITOR', 'vim', function(error) {
if (error) throw error;
});
Kind: static method of environment-variables
Summary: Update an environment variable value from an application
Access: public
Param | Type | Description |
---|---|---|
id | String | Number |
environment variable id |
value | String |
environment variable value |
Example
resin.models.environmentVariables.update(317, 'vim');
Example
resin.models.environmentVariables.update(317, 'vim', function(error) {
if (error) throw error;
});
Kind: static method of environment-variables
Summary: Remove environment variable
Access: public
Param | Type | Description |
---|---|---|
id | String | Number |
environment variable id |
Example
resin.models.environmentVariables.remove(51);
Example
resin.models.environmentVariables.remove(51, function(error) {
if (error) throw error;
});
Kind: static method of environment-variables
Summary: Check is a variable is system specific
Returns: Boolean
- Whether a variable is system specific or not
Access: public
Param | Type | Description |
---|---|---|
variable | Object |
environment variable |
Example
resin.models.environmentVariables.isSystemVariable({
name: 'RESIN_SUPERVISOR'
});
> true
Example
resin.models.environmentVariables.isSystemVariable({
name: 'EDITOR'
});
> false
Kind: static namespace of models
- .os :
object
- .getDownloadSize(deviceType, [version]) ⇒
Promise
- .getSupportedVersions(deviceType) ⇒
Promise
- .getMaxSatisfyingVersion(deviceType, versionOrRange) ⇒
Promise
- .getLastModified(deviceType, [version]) ⇒
Promise
- .download(deviceType, [version]) ⇒
Promise
- .getConfig(nameOrId, [options]) ⇒
Promise
- .getDownloadSize(deviceType, [version]) ⇒
Note! Currently only the raw (uncompressed) size is reported.
Kind: static method of os
Summary: Get OS download size estimate
Access: public
Fulfil: Number
- OS image download size, in bytes.
Param | Type | Description |
---|---|---|
deviceType | String |
device type slug |
[version] | String |
semver-compatible version or 'latest', defaults to 'latest'. The version must be the exact version number. |
Example
resin.models.os.getDownloadSize('raspberry-pi').then(function(size) {
console.log('The OS download size for raspberry-pi', size);
});
resin.models.os.getDownloadSize('raspberry-pi', function(error, size) {
if (error) throw error;
console.log('The OS download size for raspberry-pi', size);
});
Kind: static method of os
Summary: Get OS supported versions
Access: public
Fulfil: Object
- the versions information, of the following structure:
- versions - an array of strings, containing exact version numbers supported by the current environment
- recommended - the recommended version, i.e. the most recent version
that is not pre-release, can be
null
- latest - the most recent version, including pre-releases
- default - recommended (if available) or latest otherwise
Param | Type | Description |
---|---|---|
deviceType | String |
device type slug |
Example
resin.models.os.getSupportedVersions('raspberry-pi').then(function(osVersions) {
console.log('Supported OS versions for raspberry-pi', osVersions);
});
resin.models.os.getSupportedVersions('raspberry-pi', function(error, osVersions) {
if (error) throw error;
console.log('Supported OS versions for raspberry-pi', osVersions);
});
Kind: static method of os
Summary: Get the max OS version satisfying the given range
Access: public
Fulfil: String|null
- the version number, or null
if no matching versions are found
Param | Type | Description |
---|---|---|
deviceType | String |
device type slug |
versionOrRange | String |
can be one of * the exact version number, in which case it is returned if the version is supported, or null is returned otherwise, * a semver-compatible range specification, in which case the most recent satisfying version is returned if it exists, or null is returned, * 'latest' in which case the most recent version is returned, including pre-releases, * 'recommended' in which case the recommended version is returned, i.e. the most recent version excluding pre-releases, which can be null if only pre-release versions are available, * 'default' in which case the recommended version is returned if available, or latest is returned otherwise. Defaults to 'latest' . |
Example
resin.models.os.getSupportedVersions('raspberry-pi').then(function(osVersions) {
console.log('Supported OS versions for raspberry-pi', osVersions);
});
resin.models.os.getSupportedVersions('raspberry-pi', function(error, osVersions) {
if (error) throw error;
console.log('Supported OS versions for raspberry-pi', osVersions);
});
Kind: static method of os
Summary: Get the OS image last modified date
Access: public
Fulfil: Date
- last modified date
Param | Type | Description |
---|---|---|
deviceType | String |
device type slug |
[version] | String |
semver-compatible version or 'latest', defaults to 'latest'. Unsupported (unpublished) version will result in rejection. The version must be the exact version number. To resolve the semver-compatible range use resin.model.os.getMaxSatisfyingVersion . |
Example
resin.models.os.getLastModified('raspberry-pi').then(function(date) {
console.log('The raspberry-pi image was last modified in ' + date);
});
resin.models.os.getLastModified('raspberrypi3', '2.0.0').then(function(date) {
console.log('The raspberry-pi image was last modified in ' + date);
});
resin.models.os.getLastModified('raspberry-pi', function(error, date) {
if (error) throw error;
console.log('The raspberry-pi image was last modified in ' + date);
});
Kind: static method of os
Summary: Download an OS image
Access: public
Fulfil: ReadableStream
- download stream
Param | Type | Description |
---|---|---|
deviceType | String |
device type slug |
[version] | String |
semver-compatible version or 'latest', defaults to 'latest' Unsupported (unpublished) version will result in rejection. The version must be the exact version number. To resolve the semver-compatible range use resin.model.os.getMaxSatisfyingVersion . |
Example
resin.models.os.download('raspberry-pi').then(function(stream) {
stream.pipe(fs.createWriteStream('foo/bar/image.img'));
});
resin.models.os.download('raspberry-pi', function(error, stream) {
if (error) throw error;
stream.pipe(fs.createWriteStream('foo/bar/image.img'));
});
Kind: static method of os
Summary: Get an applications config.json
Access: public
Fulfil: Object
- application configuration as a JSON object.
Param | Type | Default | Description |
---|---|---|---|
nameOrId | String | Number |
application name (string) or id (number). | |
[options] | Object |
{} |
OS configuration options to use. |
[options.network] | String |
'ethernet' |
The network type that the device will use, one of 'ethernet' or 'wifi'. |
[options.appUpdatePollInterval] | Number |
How often the OS checks for updates, in minutes. | |
[options.wifiKey] | String |
The key for the wifi network the device will connect to. | |
[options.wifiSsid] | String |
The ssid for the wifi network the device will connect to. | |
[options.ip] | String |
static ip address. | |
[options.gateway] | String |
static ip gateway. | |
[options.netmask] | String |
static ip netmask. | |
[options.version] | String |
The OS version of the image. |
Example
resin.models.os.getConfig('MyApp').then(function(config) {
fs.writeFile('foo/bar/config.json', JSON.stringify(config));
});
resin.models.os.getConfig(123).then(function(config) {
fs.writeFile('foo/bar/config.json', JSON.stringify(config));
});
resin.models.os.getConfig('MyApp', function(error, config) {
if (error) throw error;
fs.writeFile('foo/bar/config.json', JSON.stringify(config));
});
Kind: static namespace of models
- .config :
object
- .getAll() ⇒
Promise
- .getDeviceTypes() ⇒
Promise
- .getDeviceOptions(deviceType) ⇒
Promise
- .getAll() ⇒
Kind: static method of config
Summary: Get all configuration
Access: public
Fulfil: Object
- configuration
Example
resin.models.config.getAll().then(function(config) {
console.log(config);
});
Example
resin.models.config.getAll(function(error, config) {
if (error) throw error;
console.log(config);
});
Kind: static method of config
Summary: Get device types
Access: public
Fulfil: Object[]
- device types
Example
resin.models.config.getDeviceTypes().then(function(deviceTypes) {
console.log(deviceTypes);
});
Example
resin.models.config.getDeviceTypes(function(error, deviceTypes) {
if (error) throw error;
console.log(deviceTypes);
})
Kind: static method of config
Summary: Get configuration/initialization options for a device type
Access: public
Fulfil: Object[]
- configuration options
Param | Type | Description |
---|---|---|
deviceType | String |
device type slug |
Example
resin.models.config.getDeviceOptions('raspberry-pi').then(function(options) {
console.log(options);
});
Example
resin.models.config.getDeviceOptions('raspberry-pi', function(error, options) {
if (error) throw error;
console.log(options);
});
Kind: static namespace of models
- .build :
object
- .get(id, [options]) ⇒
Promise
- .getAllByApplication(nameOrId, [options]) ⇒
Promise
- .get(id, [options]) ⇒
Kind: static method of build
Summary: Get a specific build
Access: public
Fulfil: Object
- build
Param | Type | Default | Description |
---|---|---|---|
id | Number |
build id | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.build.get(123).then(function(build) {
console.log(build);
});
Example
resin.models.build.get(123, function(error, build) {
if (error) throw error;
console.log(build);
});
Kind: static method of build
Summary: Get all builds from an application
Access: public
Fulfil: Object[]
- builds
Param | Type | Default | Description |
---|---|---|---|
nameOrId | String | Number |
application name (string) or id (number) | |
[options] | Object |
{} |
extra pine options to use |
Example
resin.models.build.getAllByApplication('MyApp').then(function(builds) {
console.log(builds);
});
Example
resin.models.build.getAllByApplication(123).then(function(builds) {
console.log(builds);
});
Example
resin.models.build.getAllByApplication('MyApp', function(error, builds) {
if (error) throw error;
console.log(builds);
});
Note! The billing methods are available on Resin.io exclusively.
Kind: static namespace of models
- .billing :
object
- .getAccount() ⇒
Promise
- .getPlan() ⇒
Promise
- .getBillingInfo() ⇒
Promise
- .updateBillingInfo() ⇒
Promise
- .getInvoices() ⇒
Promise
- .downloadInvoice() ⇒
Promise
- .getAccount() ⇒
Kind: static method of billing
Summary: Get the user's billing account
Access: public
Fulfil: Object
- billing account
Example
resin.models.billing.getAccount().then(function(billingAccount) {
console.log(billingAccount);
});
Example
resin.models.billing.getAccount(function(error, billingAccount) {
if (error) throw error;
console.log(billingAccount);
});
Kind: static method of billing
Summary: Get the current billing plan
Access: public
Fulfil: Object
- billing plan
Example
resin.models.billing.getPlan().then(function(billingPlan) {
console.log(billingPlan);
});
Example
resin.models.billing.getPlan(function(error, billingPlan) {
if (error) throw error;
console.log(billingPlan);
});
Kind: static method of billing
Summary: Get the current billing information
Access: public
Fulfil: Object
- billing information
Example
resin.models.billing.getBillingInfo().then(function(billingInfo) {
console.log(billingInfo);
});
Example
resin.models.billing.getBillingInfo(function(error, billingInfo) {
if (error) throw error;
console.log(billingInfo);
});
Kind: static method of billing
Summary: Update the current billing information
Access: public
Fulfil: Object
- billing information
Type | Description |
---|---|
Object |
an object containing a billing info token_id |
Example
resin.models.billing.updateBillingInfo({ token_id: 'xxxxxxx' }).then(function(billingInfo) {
console.log(billingInfo);
});
Example
resin.models.billing.updateBillingInfo({ token_id: 'xxxxxxx' }, function(error, billingInfo) {
if (error) throw error;
console.log(billingInfo);
});
Kind: static method of billing
Summary: Get the available invoices
Access: public
Fulfil: Object
- invoices
Example
resin.models.billing.getInvoices().then(function(invoices) {
console.log(invoices);
});
Example
resin.models.billing.getInvoices(function(error, invoices) {
if (error) throw error;
console.log(invoices);
});
Kind: static method of billing
Summary: Download a specific invoice
Access: public
Fulfil: Blob|ReadableStream
- blob on the browser, download stream on node
Type | Description |
---|---|
String |
an invoice number |
Example
# Browser
resin.models.billing.downloadInvoice('0000').then(function(blob) {
console.log(blob);
});
# Node
resin.models.billing.downloadInvoice('0000').then(function(stream) {
stream.pipe(fs.createWriteStream('foo/bar/invoice-0000.pdf'));
});
Kind: static namespace of resin
- .auth :
object
- .twoFactor :
object
- .isEnabled() ⇒
Promise
- .isPassed() ⇒
Promise
- .challenge(code) ⇒
Promise
- .isEnabled() ⇒
- .whoami() ⇒
Promise
- .authenticate(credentials) ⇒
Promise
- .login(credentials) ⇒
Promise
- .loginWithToken(authToken) ⇒
Promise
- .isLoggedIn() ⇒
Promise
- .createApiKey(name) ⇒
Promise
- .getToken() ⇒
Promise
- .getUserId() ⇒
Promise
- .getEmail() ⇒
Promise
- .logout() ⇒
Promise
- .register([credentials]) ⇒
Promise
- .twoFactor :
Kind: static namespace of auth
- .twoFactor :
object
- .isEnabled() ⇒
Promise
- .isPassed() ⇒
Promise
- .challenge(code) ⇒
Promise
- .isEnabled() ⇒
Kind: static method of twoFactor
Summary: Check if two factor authentication is enabled
Access: public
Fulfil: Boolean
- whether 2fa is enabled
Example
resin.auth.twoFactor.isEnabled().then(function(isEnabled) {
if (isEnabled) {
console.log('2FA is enabled for this account');
}
});
Example
resin.auth.twoFactor.isEnabled(function(error, isEnabled) {
if (error) throw error;
if (isEnabled) {
console.log('2FA is enabled for this account');
}
});
Kind: static method of twoFactor
Summary: Check if two factor authentication challenge was passed
Access: public
Fulfil: Boolean
- whether 2fa challenge was passed
Example
resin.auth.twoFactor.isPassed().then(function(isPassed) {
if (isPassed) {
console.log('2FA challenge passed');
}
});
Example
resin.auth.twoFactor.isPassed(function(error, isPassed) {
if (error) throw error;
if (isPassed) {
console.log('2FA challenge passed');
}
});
Kind: static method of twoFactor
Summary: Challenge two factor authentication
Access: public
Param | Type | Description |
---|---|---|
code | String |
code |
Example
resin.auth.twoFactor.challenge('1234');
Example
resin.auth.twoFactor.challenge('1234', function(error) {
if (error) throw error;
});
This will only work if you used module:resin.auth.login to log in.
Kind: static method of auth
Summary: Return current logged in username
Access: public
Fulfil: (String|undefined)
- username, if it exists
Example
resin.auth.whoami().then(function(username) {
if (!username) {
console.log('I\'m not logged in!');
} else {
console.log('My username is:', username);
}
});
Example
resin.auth.whoami(function(error, username) {
if (error) throw error;
if (!username) {
console.log('I\'m not logged in!');
} else {
console.log('My username is:', username);
}
});
You should use module:resin.auth.login when possible, as it takes care of saving the token and email as well.
Notice that if credentials
contains extra keys, they'll be discarted
by the server automatically.
Kind: static method of auth
Summary: Authenticate with the server
Access: protected
Fulfil: String
- session token
Param | Type | Description |
---|---|---|
credentials | Object |
in the form of email, password |
credentials.email | String |
the email |
credentials.password | String |
the password |
Example
resin.auth.authenticate(credentials).then(function(token) {
console.log('My token is:', token);
});
Example
resin.auth.authenticate(credentials, function(error, token) {
if (error) throw error;
console.log('My token is:', token);
});
If the login is successful, the token is persisted between sessions.
Kind: static method of auth
Summary: Login to Resin.io
Access: public
Param | Type | Description |
---|---|---|
credentials | Object |
in the form of email, password |
credentials.email | String |
the email |
credentials.password | String |
the password |
Example
resin.auth.login(credentials);
Example
resin.auth.login(credentials, function(error) {
if (error) throw error;
});
Login to resin with a session token or api key instead of with credentials.
Kind: static method of auth
Summary: Login to Resin.io with a token or api key
Access: public
Param | Type | Description |
---|---|---|
authToken | String |
the auth token |
Example
resin.auth.loginWithToken(authToken);
Example
resin.auth.loginWithToken(authToken, function(error) {
if (error) throw error;
});
Kind: static method of auth
Summary: Check if you're logged in
Access: public
Fulfil: Boolean
- is logged in
Example
resin.auth.isLoggedIn().then(function(isLoggedIn) {
if (isLoggedIn) {
console.log('I\'m in!');
} else {
console.log('Too bad!');
}
});
Example
resin.auth.isLoggedIn(function(error, isLoggedIn) {
if (error) throw error;
if (isLoggedIn) {
console.log('I\'m in!');
} else {
console.log('Too bad!');
}
});
This method registers a new api key for the current user with the name given.
Kind: static method of auth
Summary: Creates a new user API key
Access: public
Fulfil: String
- API key
Param | Type | Description |
---|---|---|
name | String |
the API key name |
Example
resin.auth.createApiKey(apiKeyName).then(function(apiKey) {
console.log(apiKey);
});
Example
resin.auth.createApiKey(apiKeyName, function(error, apiKey) {
if (error) throw error;
console.log(apiKey);
});
This will only work if you used module:resin.auth.login to log in.
Kind: static method of auth
Summary: Get current logged in user's raw API key or session token
Access: public
Fulfil: String
- raw API key or session token
Example
resin.auth.getToken().then(function(token) {
console.log(token);
});
Example
resin.auth.getToken(function(error, token) {
if (error) throw error;
console.log(token);
});
This will only work if you used module:resin.auth.login to log in.
Kind: static method of auth
Summary: Get current logged in user's id
Access: public
Fulfil: Number
- user id
Example
resin.auth.getUserId().then(function(userId) {
console.log(userId);
});
Example
resin.auth.getUserId(function(error, userId) {
if (error) throw error;
console.log(userId);
});
This will only work if you used module:resin.auth.login to log in.
Kind: static method of auth
Summary: Get current logged in user's email
Access: public
Fulfil: String
- user email
Example
resin.auth.getEmail().then(function(email) {
console.log(email);
});
Example
resin.auth.getEmail(function(error, email) {
if (error) throw error;
console.log(email);
});
Kind: static method of auth
Summary: Logout from Resin.io
Access: public
Example
resin.auth.logout();
Example
resin.auth.logout(function(error) {
if (error) throw error;
});
Kind: static method of auth
Summary: Register to Resin.io
Access: public
Fulfil: String
- session token
Param | Type | Default | Description |
---|---|---|---|
[credentials] | Object |
{} |
in the form of username, password and email |
credentials.email | String |
the email | |
credentials.password | String |
the password |
Example
resin.auth.register({
email: '[email protected]',
password: 'secret'
}).then(function(token) {
console.log(token);
});
Example
resin.auth.register({
email: '[email protected]',
password: 'secret'
}, function(error, token) {
if (error) throw error;
console.log(token);
});
Kind: static namespace of resin
- .logs :
object
- .subscribe(uuidOrId) ⇒
Promise
- .history(uuidOrId, [options]) ⇒
Promise
- .historySinceLastClear(uuidOrId, [options]) ⇒
Promise
- .clear(uuidOrId) ⇒
Promise
- .LogSubscription :
EventEmitter
- .subscribe(uuidOrId) ⇒
Connects to the stream of devices logs, returning a LogSubscription, which can be used to listen for logs as they appear, line by line.
Kind: static method of logs
Summary: Subscribe to device logs
Access: public
Fulfil: LogSubscription
Todo
- We should consider making this a readable stream.
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.logs.subscribe('7cf02a6').then(function(logs) {
logs.on('line', function(line) {
console.log(line);
});
logs.on('clear', function() {
console.clear();
});
});
Example
resin.logs.subscribe(123).then(function(logs) {
logs.on('line', function(line) {
console.log(line);
});
logs.on('clear', function() {
console.clear();
});
});
Example
resin.logs.subscribe('7cf02a6', function(error, logs) {
if (error) throw error;
logs.on('line', function(line) {
console.log(line);
});
});
Note: the default number of logs retrieved is 100.
To get a different number pass the { count: N }
to the options param.
Also note that the actual number of log lines can be bigger as the
Resin.io supervisor can combine lines sent in a short time interval
Kind: static method of logs
Summary: Get device logs history
Access: public
Fulfil: Object[]
- history lines
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
[options] | Object |
any options supported by https://www.pubnub.com/docs/nodejs-javascript/api-reference#history |
Example
resin.logs.history('7cf02a6').then(function(lines) {
lines.forEach(function(line) {
console.log(line);
});
});
Example
resin.logs.history(123).then(function(lines) {
lines.forEach(function(line) {
console.log(line);
});
});
Example
resin.logs.history('7cf02a6', { count: 20 }, function(error, lines) {
if (error) throw error;
lines.forEach(function(line) {
console.log(line);
});
});
Note: the default number of logs retrieved is 200.
To get a different number pass the { count: N }
to the options param.
Also note that the actual number of log lines can be bigger as the
Resin.io supervisor can combine lines sent in a short time interval
Kind: static method of logs
Summary: Get device logs history after the most recent clear request
Access: public
Fulfil: Object[]
- history lines
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
[options] | Object |
any options supported by https://www.pubnub.com/docs/nodejs-javascript/api-reference#history |
Example
resin.logs.historySinceLastClear('7cf02a6', { count: 20 }).then(function(lines) {
lines.forEach(function(line) {
console.log(line);
});
});
Example
resin.logs.historySinceLastClear(123).then(function(lines) {
lines.forEach(function(line) {
console.log(line);
});
});
Example
resin.logs.historySinceLastClear('7cf02a6', function(error, lines) {
if (error) throw error;
lines.forEach(function(line) {
console.log(line);
});
});
Kind: static method of logs
Summary: Clear device logs history
Access: public
Param | Type | Description |
---|---|---|
uuidOrId | String | Number |
device uuid (string) or id (number) |
Example
resin.logs.clear('7cf02a6').then(function() {
console.log('OK');
});
Example
resin.logs.clear(123).then(function() {
console.log('OK');
});
The log subscription emits events as log data arrives.
You can get a LogSubscription for a given device by calling resin.logs.subscribe(deviceId)
Kind: static typedef of logs
- .LogSubscription :
EventEmitter
Disconnect from the logs feed and stop receiving any future events on this emitter.
Kind: static method of LogSubscription
Summary: Unsubscribe from device logs
Access: public
Example
logs.unsubscribe();
Kind: event emitted by LogSubscription
Summary: Event fired when a new line of log output is available
Example
logs.on('line', function(line) {
console.log(line);
});
Kind: event emitted by LogSubscription
Summary: Event fired when the logs have been cleared
Example
logs.on('clear', function() {
console.clear();
});
Kind: event emitted by LogSubscription
Summary: Event fired when an error has occured reading the device logs
Example
logs.on('error', function(error) {
console.error(error);
});
Kind: static namespace of resin
- .settings :
object
- .get([key]) ⇒
Promise
- .getAll() ⇒
Promise
- .get([key]) ⇒
Kind: static method of settings
Summary: Get a single setting. Only implemented in Node.js
Access: public
Fulfil: *
- setting value
Param | Type | Description |
---|---|---|
[key] | String |
setting key |
Example
resin.settings.get('apiUrl').then(function(apiUrl) {
console.log(apiUrl);
});
Example
resin.settings.get('apiUrl', function(error, apiUrl) {
if (error) throw error;
console.log(apiUrl);
});
Kind: static method of settings
Summary: Get all settings Only implemented in Node.js
Access: public
Fulfil: Object
- settings
Example
resin.settings.getAll().then(function(settings) {
console.log(settings);
});
Example
resin.settings.getAll(function(error, settings) {
if (error) throw error;
console.log(settings);
});
Set options that are used by calls to resin.fromSharedOptions()
.
The options accepted are the same as those used in the main SDK factory function.
If you use this method, it should be called as soon as possible during app
startup and before any calls to fromSharedOptions()
are made.
Kind: static method of resin
Summary: Set shared default options
Access: public
Params: Object
opts - The shared default options
Example
resin.setSharedOptions({
apiUrl: 'https://api.resin.io/',
imageMakerUrl: 'https://img.resin.io/',
isBrowser: true,
});
Create an SDK instance using shared default options set using the setSharedOptions()
method.
If options have not been set using this method, then this method will use the
same defaults as the main SDK factory function.
Kind: static method of resin
Summary: Create an SDK instance using shared default options
Access: public
Params: Object
opts - The shared default options
Example
const sdk = resin.fromSharedOptions();