Improve this doc

Resin Node.js SDK

resin : object

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.models : object

Kind: static namespace of resin

models.application : object

Kind: static namespace of models

application.getAll() ⇒ Promise

Kind: static method of application
Summary: Get all applications
Access: public
Fulfil: Object[] - applications
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);
});

application.get(name) ⇒ Promise

Kind: static method of application
Summary: Get a single application
Access: public
Fulfil: Object - application

Param Type Description
name String application name

Example

resin.models.application.get('MyApp').then(function(application) {
    console.log(application);
});

Example

resin.models.application.get('MyApp', function(error, application) {
    if (error) throw error;
    console.log(application);
});

application.has(name) ⇒ Promise

Kind: static method of application
Summary: Check if an application exist
Access: public
Fulfil: Boolean - has application

Param Type Description
name String application name

Example

resin.models.application.has('MyApp').then(function(hasApp) {
    console.log(hasApp);
});

Example

resin.models.application.has('MyApp', function(error, hasApp) {
    if (error) throw error;
    console.log(hasApp);
});

application.hasAny() ⇒ Promise

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);
});

application.getById(id) ⇒ Promise

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);
});

application.create(name, deviceType) ⇒ Promise

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

Example

resin.models.application.create('My App', 'raspberry-pi').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);
});

application.remove(name) ⇒ Promise

Kind: static method of application
Summary: Remove application
Access: public

Param Type Description
name String application name

Example

resin.models.application.remove('MyApp');

Example

resin.models.application.remove('MyApp', function(error) {
    if (error) throw error;
});

application.restart(name) ⇒ Promise

Kind: static method of application
Summary: Restart application
Access: public

Param Type Description
name String application name

Example

resin.models.application.restart('MyApp');

Example

resin.models.application.restart('MyApp', function(error) {
    if (error) throw error;
});

application.getApiKey(name) ⇒ Promise

Kind: static method of application
Summary: Get the API key for a specific application
Access: public
Fulfil: String - api key

Param Type Description
name String application name

Example

resin.models.application.getApiKey('MyApp').then(function(apiKey) {
    console.log(apiKey);
});

Example

resin.models.application.getApiKey('MyApp', function(error, apiKey) {
    if (error) throw error;
    console.log(apiKey);
});

models.device : object

Kind: static namespace of models

device.getAll() ⇒ Promise

Kind: static method of device
Summary: Get all devices
Access: public
Fulfil: Object[] - devices
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);
});

device.getAllByApplication(name) ⇒ Promise

Kind: static method of device
Summary: Get all devices by application
Access: public
Fulfil: Object[] - devices

Param Type Description
name String application name

Example

resin.models.device.getAllByApplication('MyApp').then(function(devices) {
    console.log(devices);
});

Example

resin.models.device.getAllByApplication('MyApp', function(error, devices) {
    if (error) throw error;
    console.log(devices);
});

device.get(uuid) ⇒ Promise

Kind: static method of device
Summary: Get a single device
Access: public
Fulfil: Object - device

Param Type Description
uuid String device uuid

Example

resin.models.device.get('7cf02a6').then(function(device) {
    console.log(device);
})

Example

resin.models.device.get('7cf02a6', function(error, device) {
    if (error) throw error;
    console.log(device);
});

device.getByName(name) ⇒ Promise

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);
});

device.getName(uuid) ⇒ Promise

Kind: static method of device
Summary: Get the name of a device
Access: public
Fulfil: String - device name

Param Type Description
uuid String device uuid

Example

resin.models.device.getName('7cf02a6').then(function(deviceName) {
    console.log(deviceName);
});

Example

resin.models.device.getName('7cf02a6', function(error, deviceName) {
    if (error) throw error;
    console.log(deviceName);
});

device.getApplicationName(uuid) ⇒ Promise

Kind: static method of device
Summary: Get application name
Access: public
Fulfil: String - application name

Param Type Description
uuid String device uuid

Example

resin.models.device.getApplicationName('7cf02a6').then(function(applicationName) {
    console.log(applicationName);
});

Example

resin.models.device.getApplicationName('7cf02a6', function(error, applicationName) {
    if (error) throw error;
    console.log(applicationName);
});

device.getApplicationInfo(uuid) ⇒ Promise

Kind: static method of device
Summary: Get application container information
Access: public
Fulfil: Object - application info

Param Type Description
uuid String device uuid

Example

resin.models.device.getApplicationInfo('7cf02a6').then(function(appInfo) {
    console.log(appInfo);
});

Example

resin.models.device.getApplicationInfo('7cf02a6', function(error, appInfo) {
    if (error) throw error;
    console.log(appInfo);
});

device.has(uuid) ⇒ Promise

Kind: static method of device
Summary: Check if a device exists
Access: public
Fulfil: Boolean - has device

Param Type Description
uuid String device uuid

Example

resin.models.device.has('7cf02a6').then(function(hasDevice) {
    console.log(hasDevice);
});

Example

resin.models.device.has('7cf02a6', function(error, hasDevice) {
    if (error) throw error;
    console.log(hasDevice);
});

device.isOnline(uuid) ⇒ Promise

Kind: static method of device
Summary: Check if a device is online
Access: public
Fulfil: Boolean - is device online

Param Type Description
uuid String device uuid

Example

resin.models.device.isOnline('7cf02a6').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);
});

device.getLocalIPAddresses(uuid) ⇒ Promise

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
uuid String device uuid

Example

resin.models.device.getLocalIPAddresses('7cf02a6').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);
    });
});

device.remove(uuid) ⇒ Promise

Kind: static method of device
Summary: Remove device
Access: public

Param Type Description
uuid String device uuid

Example

resin.models.device.remove('7cf02a6');

Example

resin.models.device.remove('7cf02a6', function(error) {
    if (error) throw error;
});

device.identify(uuid) ⇒ Promise

Kind: static method of device
Summary: Identify device
Access: public

Param Type Description
uuid String device uuid

Example

resin.models.device.identify('7cf02a6');

Example

resin.models.device.identify('7cf02a6', function(error) {
    if (error) throw error;
});

device.rename(uuid, newName) ⇒ Promise

Kind: static method of device
Summary: Rename device
Access: public

Param Type Description
uuid String device uuid
newName String the device new name

Example

resin.models.device.rename('7cf02a6', 'NewName');

Example

resin.models.device.rename('7cf02a6', 'NewName', function(error) {
    if (error) throw error;
});

device.note(uuid, note) ⇒ Promise

Kind: static method of device
Summary: Note a device
Access: public

Param Type Description
uuid String device uuid
note String the note

Example

resin.models.device.note('7cf02a6', 'My useful note');

Example

resin.models.device.note('7cf02a6', 'My useful note', function(error) {
    if (error) throw error;
});

device.move(uuid, application) ⇒ Promise

Kind: static method of device
Summary: Move a device to another application
Access: public

Param Type Description
uuid String device uuid
application String application name

Example

resin.models.device.move('7cf02a6', 'MyApp');

Example

resin.models.device.move('7cf02a6', 'MyApp', function(error) {
    if (error) throw error;
});

device.startApplication(uuid) ⇒ Promise

Kind: static method of device
Summary: Start application on device
Access: public
Fulfil: String - application container id

Param Type Description
uuid String device uuid

Example

resin.models.device.startApplication('7cf02a6').then(function(containerId) {
    console.log(containerId);
});

Example

resin.models.device.startApplication('7cf02a6', function(error, containerId) {
    if (error) throw error;
    console.log(containerId);
});

device.stopApplication(uuid) ⇒ Promise

Kind: static method of device
Summary: Stop application on device
Access: public
Fulfil: String - application container id

Param Type Description
uuid String device uuid

Example

resin.models.device.stopApplication('7cf02a6').then(function(containerId) {
    console.log(containerId);
});

Example

resin.models.device.stopApplication('7cf02a6', function(error, containerId) {
    if (error) throw error;
    console.log(containerId);
});

device.restartApplication(uuid) ⇒ Promise

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
uuid String device uuid

Example

resin.models.device.restartApplication('7cf02a6');

Example

resin.models.device.restartApplication('7cf02a6', function(error) {
    if (error) throw error;
});

device.restart(uuid) ⇒ Promise

Deprecated

Kind: static method of device
Summary: Restart application on device.
Access: public
See: restartApplication

Param Type Description
uuid String device uuid

device.reboot(uuid, [options]) ⇒ Promise

Kind: static method of device
Summary: Reboot device
Access: public

Param Type Default Description
uuid String device uuid
[options] Object options
[options.force] Boolean false override update lock

Example

resin.models.device.reboot('7cf02a6');

Example

resin.models.device.reboot('7cf02a6', function(error) {
    if (error) throw error;
});

device.shutdown(uuid, [options]) ⇒ Promise

Kind: static method of device
Summary: Shutdown device
Access: public

Param Type Default Description
uuid String device uuid
[options] Object options
[options.force] Boolean false override update lock

Example

resin.models.device.shutdown('7cf02a6');

Example

resin.models.device.shutdown('7cf02a6', function(error) {
    if (error) throw error;
});

device.purge(uuid) ⇒ Promise

This function clears the user application's /data directory.

Kind: static method of device
Summary: Purge device
Access: public

Param Type Description
uuid String device uuid

Example

resin.models.device.purge('7cf02a6');

Example

resin.models.device.purge('7cf02a6', function(error) {
    if (error) throw error;
});

device.update(uuid, options) ⇒ Promise

Kind: static method of device
Summary: Trigger an update check on the supervisor
Access: public

Param Type Default Description
uuid String device uuid
options Object options
[options.force] Boolean false override update lock

Example

resin.models.device.update('7cf02a6', {
    force: true
});

Example

resin.models.device.update('7cf02a6', {
    force: true
}, function(error) {
    if (error) throw error;
});

device.getDisplayName(deviceTypeSlug) ⇒ Promise

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
});

device.getDeviceSlug(deviceTypeName) ⇒ Promise

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
});

device.getSupportedDeviceTypes() ⇒ Promise

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);
    });
});

device.getManifestBySlug(slug) ⇒ Promise

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);
});

device.getManifestByApplication(applicationName) ⇒ Promise

Kind: static method of device
Summary: Get a device manifest by application name
Access: public
Fulfil: Object - device manifest

Param Type Description
applicationName String application name

Example

resin.models.device.getManifestByApplication('MyApp').then(function(manifest) {
    console.log(manifest);
});

Example

resin.models.device.getManifestByApplication('MyApp', function(error, manifest) {
    if (error) throw error;
    console.log(manifest);
});

device.generateUUID() ⇒ Promise

Kind: static method of device
Summary: Generate a random device UUID
Access: public
Fulfil: String - a generated UUID
Example

resin.models.device.generateUUID().then(function(uuid) {
    console.log(uuid);
});

Example

resin.models.device.generateUUID(function(error, uuid) {
    if (error) throw error;
    console.log(uuid);
});

device.register(applicationName, uuid) ⇒ Promise

Kind: static method of device
Summary: Register a new device with a Resin.io application
Access: public
Fulfil: Object - device

Param Type Description
applicationName String application name
uuid String device uuid

Example

resin.models.device.generateUUID().then(function(uuid) {
    resin.models.device.register('MyApp', uuid).then(function(device) {
        console.log(device);
    });
});

Example

resin.models.device.generateUUID(function(error, uuid) {
    if (error) throw error;

    resin.models.device.register('MyApp', uuid, function(error, device) {
        if (error) throw error;

        console.log(device);
    });
});

device.hasDeviceUrl(uuid) ⇒ Promise

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
uuid String device uuid

Example

resin.models.device.hasDeviceUrl('7cf02a6').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');
    }
});

device.getDeviceUrl(uuid) ⇒ Promise

Kind: static method of device
Summary: Get a device url
Access: public
Fulfil: String - device url

Param Type Description
uuid String device uuid

Example

resin.models.device.getDeviceUrl('7cf02a6').then(function(url) {
    console.log(url);
});

Example

resin.models.device.getDeviceUrl('7cf02a6', function(error, url) {
    if (error) throw error;
    console.log(url);
});

device.enableDeviceUrl(uuid) ⇒ Promise

Kind: static method of device
Summary: Enable device url for a device
Access: public

Param Type Description
uuid String device uuid

Example

resin.models.device.enableDeviceUrl('7cf02a6');

Example

resin.models.device.enableDeviceUrl('7cf02a6', function(error) {
    if (error) throw error;
});

device.disableDeviceUrl(uuid) ⇒ Promise

Kind: static method of device
Summary: Disable device url for a device
Access: public

Param Type Description
uuid String device uuid

Example

resin.models.device.disableDeviceUrl('7cf02a6');

Example

resin.models.device.disableDeviceUrl('7cf02a6', function(error) {
    if (error) throw error;
});

device.enableTcpPing(uuid) ⇒ Promise

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
uuid String device uuid

Example

resin.models.device.enableTcpPing('7cf02a6');

Example

resin.models.device.enableTcpPing('7cf02a6', function(error) {
    if (error) throw error;
});

device.disableTcpPing(uuid) ⇒ Promise

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
uuid String device uuid

Example

resin.models.device.disableTcpPing('7cf02a6');

Example

resin.models.device.disableTcpPing('7cf02a6', function(error) {
    if (error) throw error;
});

device.ping(uuid) ⇒ Promise

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
uuid String device uuid

Example

resin.models.device.ping('7cf02a6');

Example

resin.models.device.ping('7cf02a6', function(error) {
    if (error) throw error;
});

device.getStatus(uuid) ⇒ Promise

Kind: static method of device
Summary: Get the status of a device
Access: public
Fulfil: String - device statud

Param Type Description
uuid String device uuid

Example

resin.models.device.getStatus('7cf02a6').then(function(status) {
    console.log(status);
});

Example

resin.models.device.getStatus('7cf02a6', function(error, status) {
    if (error) throw error;
    console.log(status);
});

models.key : object

Kind: static namespace of models

key.getAll() ⇒ Promise

Kind: static method of key
Summary: Get all ssh keys
Access: public
Fulfil: Object[] - ssh keys
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);
});

key.get(id) ⇒ Promise

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);
});

key.remove(id) ⇒ Promise

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;
});

key.create(title, key) ⇒ Promise

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);
});

models.environment-variables : object

Kind: static namespace of models

environment-variables.device : object

Kind: static namespace of environment-variables

device.getAll(uuid) ⇒ Promise

Kind: static method of device
Summary: Get all device environment variables
Access: public
Fulfil: Object[] - device environment variables

Param Type Description
uuid String device uuid

Example

resin.models.environmentVariables.device.getAll('7cf02a6').then(function(environmentVariables) {
    console.log(environmentVariables);
});

Example

resin.models.environmentVariables.device.getAll('7cf02a6', function(error, environmentVariables) {
    if (error) throw error;
    console.log(environmentVariables)
});

device.create(uuid, name, value) ⇒ Promise

Kind: static method of device
Summary: Create a device environment variable
Access: public

Param Type Description
uuid String device uuid
name String environment variable name
value String environment variable value

Example

resin.models.environmentVariables.device.create('7cf02a6', 'EDITOR', 'vim');

Example

resin.models.environmentVariables.device.create('7cf02a6', 'EDITOR', 'vim', function(error) {
    if (error) throw error;
});

device.update(id, value) ⇒ Promise

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;
});

device.remove(id) ⇒ Promise

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;
});

environment-variables.getAll(applicationName) ⇒ Promise

Kind: static method of environment-variables
Summary: Get all environment variables by application
Access: public
Fulfil: Object[] - environment variables

Param Type Description
applicationName String application name

Example

resin.models.environmentVariables.getAllByApplication('MyApp').then(function(environmentVariables) {
    console.log(environmentVariables);
});

Example

resin.models.environmentVariables.getAllByApplication('MyApp', function(error, environmentVariables) {
    if (error) throw error;
    console.log(environmentVariables);
});

environment-variables.create(applicationName, name, value) ⇒ Promise

Kind: static method of environment-variables
Summary: Create an environment variable for an application
Access: public

Param Type Description
applicationName String application name
name String environment variable name
value String environment variable value

Example

resin.models.environmentVariables.create('MyApp', 'EDITOR', 'vim');

Example

resin.models.environmentVariables.create('MyApp', 'EDITOR', 'vim', function(error) {
    if (error) throw error;
});

environment-variables.update(id, value) ⇒ Promise

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;
});

environment-variables.remove(id) ⇒ Promise

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;
});

environment-variables.isSystemVariable(variable) ⇒ Boolean

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

models.os : object

Kind: static namespace of models

os.getLastModified(deviceType) ⇒ Promise

Kind: static method of os
Summary: Get OS image last modified date
Access: public
Fulfil: Date - last modified date

Param Type Description
deviceType String device type slug

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('raspberry-pi', function(error, date) {
    if (error) throw error;
    console.log('The raspberry-pi image was last modified in ' + date);
});

os.download(deviceType) ⇒ Promise

Kind: static method of os
Summary: Download an OS image
Access: public
Fulfil: ReadableStream - download stream

Param Type Description
deviceType String device type slug

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'));
});

models.config : object

Kind: static namespace of models

config.getAll() ⇒ Promise

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);
});

config.getDeviceTypes() ⇒ Promise

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);
})

config.getDeviceOptions(deviceType) ⇒ Promise

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);
});

models.build : object

Kind: static namespace of models

build.getAllByApplication(name) ⇒ Promise

Kind: static method of build
Summary: Get all builds from an application
Access: public
Fulfil: Object[] - builds

Param Type Description
name String application name

Example

resin.models.build.getAllByApplication('MyApp').then(function(builds) {
        console.log(builds);
});

Example

resin.models.build.getAllByApplication('MyApp', function(error, builds) {
        if (error) throw error;
        console.log(builds);
});

resin.auth : object

Kind: static namespace of resin

auth.twoFactor : object

Kind: static namespace of auth

twoFactor.isEnabled() ⇒ Promise

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');
    }
});

twoFactor.isPassed() ⇒ Promise

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');
    }
});

twoFactor.challenge(code) ⇒ Promise

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;
});

auth.whoami() ⇒ Promise

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);
    }
});

auth.authenticate(credentials) ⇒ Promise

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);
});

auth.login(credentials) ⇒ Promise

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;
});

auth.loginWithToken(token) ⇒ Promise

Login to resin with a session token instead of with credentials.

Kind: static method of auth
Summary: Login to Resin.io with a token
Access: public

Param Type Description
token String the auth token

Example

resin.auth.loginWithToken(token);

Example

resin.auth.loginWithToken(token, function(error) {
    if (error) throw error;
});

auth.isLoggedIn() ⇒ Promise

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!');
    }
});

auth.getToken() ⇒ Promise

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 token
Access: public
Fulfil: String - 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);
});

auth.getUserId() ⇒ Promise

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);
});

auth.getEmail() ⇒ Promise

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);
});

auth.logout() ⇒ Promise

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;
});

auth.register([credentials]) ⇒ Promise

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);
});

resin.logs : object

Kind: static namespace of resin

logs.subscribe(uuid) ⇒ Promise

The logs object yielded by this function emits the following events:

  • line: when a log line is received.
  • error: when an error happens.

Kind: static method of logs
Summary: Subscribe to device logs
Access: public
Fulfil: EventEmitter - logs
Todo

  • [ ] We should consider making this a readable stream.
Param Type Description
uuid String device uuid

Example

resin.logs.subscribe('7cf02a6').then(function(logs) {
    logs.on('line', function(line) {
        console.log(line);
    });
});

Example

resin.logs.subscribe('7cf02a6', function(error, logs) {
    if (error) throw error;

    logs.on('line', function(line) {
        console.log(line);
    });
});

logs.history(uuid) ⇒ Promise

Kind: static method of logs
Summary: Get device logs history
Access: public
Fulfil: String[] - history lines

Param Type Description
uuid String device uuid

Example

resin.logs.history('7cf02a6').then(function(lines) {
    lines.forEach(function(line) {
        console.log(line);
    });
});

Example

resin.logs.history('7cf02a6', function(error, lines) {
    if (error) throw error;

    lines.forEach(function(line) {
        console.log(line);
    });
});

resin.settings : object

Kind: static namespace of resin

settings.get([key]) ⇒ Promise

Kind: static method of settings
Summary: Get a single setting
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);
});

settings.getAll() ⇒ Promise

Kind: static method of settings
Summary: Get all settings
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);
});