Particle API JS (Javascript SDK)
ParticleJS is JavaScript library for the Particle Device Cloud API for Node.js and the browser. It's open source so you can edit, change or even send in pull requests if you want to share!
This page contains examples to get started using the library.
For more details, see the detailed reference below and check the examples folder on GitHub.
Installation
Node.js
First, make sure you have node.js installed!
Next, open a command prompt or terminal, and install by typing:
$ npm install particle-api-js
Browser
Particle API JS can be included using bower:
$ bower install particle-api-js
Alternately, you can pull in Particle API JS from the JSDelivr and simply include the script in your HTML.
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/particle-api-js@10/dist/particle.min.js">
</script>
Now you will have a Particle object available that you can use in your application.
Responses
All functions in this library return promises.
particle.login({username: 'email@example.com', password: 'pass'}).then(
function(data){
console.log('API call completed on promise resolve: ', data.body.access_token);
},
function(err) {
console.log('API call completed on promise fail: ', err);
}
);
Examples
Here are some common use cases of using the functions in the Javascript library.
Logging in
login
You can create an account here. Use the token from login as the auth parameter in other calls.
var Particle = require('particle-api-js');
var particle = new Particle();
var token;
particle.login({username: 'user@email.com', password: 'pass'}).then(
function(data) {
token = data.body.access_token;
},
function (err) {
console.log('Could not log in.', err);
}
);
Device management
listDevices
List devices for a user with listDevices.
var token; // from result of particle.login
var devicesPr = particle.listDevices({ auth: token });
devicesPr.then(
function(devices){
console.log('Devices: ', devices);
},
function(err) {
console.log('List devices call failed: ', err);
}
);
callFunction
Call a function in device with callFunction.
var fnPr = particle.callFunction({ deviceId: 'DEVICE_ID', name: 'brew', argument: 'D0:HIGH', auth: token });
fnPr.then(
function(data) {
console.log('Function called succesfully:', data);
}, function(err) {
console.log('An error occurred:', err);
});
The function needs to be defined in the firmware uploaded to the device and registered to the Particle cloud.
You pass along the name of the function and the params.
If the function call succeeds, data.return_value is the value returned by the function call on the Particle device.
claimDevice
Claims device and adds it to the user account with claimDevice
particle.claimDevice({ deviceId: 'DEVICE_ID', auth: token }).then(function(data) {
console.log('device claim data:', data);
}, function(err) {
console.log('device claim err:', err);
});
flashDevice
Flash firmware to device with flashDevice
particle.flashDevice({ deviceId: 'DEVICE_ID', files: { file1: './path/file1' }, auth: token }).then(function(data) {
console.log('Device flashing started successfully:', data);
}, function(err) {
console.log('An error occurred while flashing the device:', err);
});
getDevice
Gets all attributes for the device with getDevice
var devicesPr = particle.getDevice({ deviceId: 'DEVICE_ID', auth: token });
devicesPr.then(
function(data){
console.log('Device attrs retrieved successfully:', data);
},
function(err) {
console.log('API call failed: ', err);
}
);
getVariable
Gets a variable value for the device with getVariable
particle.getVariable({ deviceId: 'DEVICE_ID', name: 'temp', auth: token }).then(function(data) {
console.log('Device variable retrieved successfully:', data);
}, function(err) {
console.log('An error occurred while getting attrs:', err);
});
The variable needs to be defined in your device's code.
If getting the variable succeeds, data.body.result is the value of the variable on the Particle device.
removeDevice
Removes device from the user account with removeDevice
particle.removeDevice({ deviceId: 'DEVICE_ID', auth: token }).then(function(data) {
console.log('remove call response:', data);
}, function(err) {
console.log('An error occurred while removing:', err);
});
renameDevice
Renames device for the user account with renameDevice
particle.renameDevice({ deviceId: 'DEVICE_ID', name: 'new-name', auth: token }).then(function(data) {
console.log('Device renamed successfully:', data);
}, function(err) {
console.log('An error occurred while renaming device:', err);
});
signalDevice
Send a signal to the device to shout rainbows with signalDevice
particle.signalDevice({ deviceId: 'DEVICE_ID', signal: true, auth: token }).then(function(data) {
console.log('Device is shouting rainbows:', data);
}, function(err) {
console.log('Error sending a signal to the device:', err);
});
Send a signal to the device to stop shouting rainbows
particle.signalDevice({ deviceId: 'DEVICE_ID', signal: false, auth: token }).then(function(data) {
console.log('The LED is back to normal:', data);
}, function(err) {
console.log('Error sending a signal to the device:', err);
});
sendPublicKey
Send public key for a device to the cloud with sendPublicKey
particle.sendPublicKey({ deviceId: 'DEVICE_ID', key: 'key', auth: token }).then(function(data) {
console.log('Public key sent successfully:', data);
}, function(err) {
console.log('Error sending public key to the device:', err);
});
getEventStream
Get event listener to an stream in the Particle cloud with getEventStream
//Get events filtered by name
particle.getEventStream({ name: 'x', auth: token}).then(function(stream) {
stream.on('event', function(data) {
console.log("Event: ", data);
});
});
//Get your devices events
particle.getEventStream({ deviceId: 'mine', auth: token }).then(function(stream) {
stream.on('event', function(data) {
console.log("Event: ", data);
});
});
//Get test event for specific device
particle.getEventStream({ deviceId: 'DEVICE_ID', name: 'test', auth: token }).then(function(stream) {
stream.on('event', function(data) {
console.log("Event: ", data);
});
});
data is an object with the following properties
{
"name":"Uptime",
"data":"5:28:54",
"ttl":"60",
"published_at":"2014-MM-DDTHH:mm:ss.000Z",
"coreid":"012345678901234567890123"
}
When a network error occurs or the event stream has not received a heartbeat from the Particle API in 13 seconds, the event stream will disconnect and attempt to reconnect after 2 seconds. To customize the reconnection behavior, close the stream in the disconnect handler.
// This is not a functional reconnection implementation, only an illustration of the various events
let attempts = 10;
particle.getEventStream(options).then(function(stream) {
stream.on('disconnect', function() {
console.log('Disconnected from Particle event stream');
attempts--;
if (attempts <= 0) {
console.log('Giving up reconnecting');
stream.abort();
}
});
stream.on('reconnect', function() {
console.log('Attempting to reconnect to Particle event stream');
});
stream.on('reconnect-success', function() {
console.log('Reconnected to Particle event stream');
attempts = 10;
});
stream.on('reconnect-error', function(error) {
console.log('Failed to reconnect to Particle event stream', error);
});
});
In case your event handler throws an exception, the error event will be emitted.
particle.getEventStream(options).then(function(stream) {
stream.on('event', function(data) {
throw new Error('oops');
});
stream.on('error', function(error) {
console.log('Error in handler', error);
});
});
publishEvent
Register an event stream in the Particle cloud with publishEvent
var publishEventPr = particle.publishEvent({ name: 'test', data: JSON.stringify({ ok: true }), auth: token });
publishEventPr.then(
function(data) {
if (data.body.ok) { console.log("Event published succesfully") }
},
function(err) {
console.log("Failed to publish event: " + err)
}
);
Working with code
compileCode
Compiles files in the Particle cloud with compileCode
var ccPr = particle.compileCode({ files: { 'main.cpp': './project/main.cpp', 'my_lib/lib.cpp': './project/my_lib/lib.cpp' }, auth: token });
ccPr.then(
function(data) {
console.log('Code compilation started successfully:', data);
}, function(err) {
console.log('An error occurred while compiling the code:', err);
});
Flashing
Flash firmware to a device with flashDevice
User management
createUser
Creates a user in the Particle cloud with createUser
particle.createUser({ username: 'example@email.com', password: 'pass' }).then(function(data) {
We try to login and get back an accessToken to verify user creation
var loginPromise = particle.login('example@email.com', 'pass');
We'll use promises to check the result of the login process
loginPromise.then(
function(data) {
console.log('Login successful! access_token:', data.access_token);
},
function(err) {
console.log('Login failed:', err);
}
);
}
});
listAccessTokens
Lists access tokens from the Particle cloud for the specified user with listAccessTokens
particle.listAccessTokens({ username: 'u@m.com', password: 'pass' }).then(function(data) {
console.log('data on listing access tokens: ', data);
}, function(err) {
console.log('error on listing access tokens: ', err);
});
deleteAccessToken
Removes an access token from the Particle cloud for the specified user with deleteAccessToken
particle.deleteAccessToken({ username: 'u@m.com', password: 'pass', token: 'token' }).then(function(data) {
console.log('data on deleting accessToken: ', data);
}, function(err) {
console.log('error on deleting accessToken: ', err);
});
Product support
If you are a product creator you can use the Javascript library to manage devices, firmware, integrations, and more.
Many of the functions in the Javascript library accept a product parameter. Pass your product ID number (such as 4567) or the slug (such as myproduct-v100) to make that function act on that product.
Detailed reference
Here a full reference of every function available in the Javascript client library.
constructor
Contructor for the Cloud API wrapper.
Create a new Particle object and call methods below on it.
Parameters
optionsObject Options for this API call Options to be used for all requests (see Defaults) (optional, default{})
login
Login to Particle Cloud using an existing Particle acccount.
Parameters
optionsObject Options for this API calloptions.usernameString Username for the Particle accountoptions.passwordString Password for the Particle accountoptions.tokenDurationNumber How long the access token should last in seconds (optional, defaultthis.tokenDuration)options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextNumber? Request context
Returns Promise A promise
sendOtp
If login failed with an 'mfa_required' error, this must be called with a valid OTP code to login
Parameters
optionsObject Options for this API calloptions.mfaTokenString Given as 'mfa_token' in the error body of.login().options.otpString Current one-time-password generated from the authentication applicationoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextNumber? Request context
Returns Promise A promise
enableMfa
Enable MFA on the currently logged in user
Parameters
optionsObject Options for this API call
Returns Promise A promise
confirmMfa
Confirm MFA for the user. This must be called with current TOTP code, determined from the results of enableMfa(). You will be prompted to enter an OTP code every time you login after enrollment is confirmed.
Parameters
optionsObject Options for this API calloptions.mfaTokenObject Token given from previous step tooptions.otpObject Current one-time-password generated from the authentication appoptions.invalidateTokensBoolean Should all tokens be invalidated (optional, defaultfalse)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
disableMfa
Disable MFA for the user.
Parameters
optionsObject Options for this API call
Returns Promise A promise
createCustomer
Create Customer for Product.
Parameters
optionsObject Options for this API calloptions.emailString Username for the Particle accountoptions.passwordString Password for the Particle accountoptions.productString Create the customer in this product ID or slugoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
loginAsClientOwner
Login to Particle Cloud using an OAuth client.
Parameters
optionsObject Options for this API call
Returns Promise A promise
createUser
Create a user account for the Particle Cloud
Parameters
optionsObject Options for this API calloptions.usernameString Email of the new useroptions.passwordString Passwordoptions.accountInfoString Object that contains account information fields such as user real name, company name, business account flag etcoptions.utmObject? Object that contains info about the campaign that lead to this user creationoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
verifyUser
Verify new user account via verification email
Parameters
optionsObject Options for this API call
Returns Promise A promise
resetPassword
Send reset password email for a Particle Cloud user account
Parameters
optionsObject Options for this API call
Returns Promise A promise
deleteAccessToken
Revoke an access token
Parameters
optionsObject Options for this API call
Returns Promise A promise
deleteCurrentAccessToken
Revoke the current session access token
Parameters
optionsObject Options for this API call
Returns Promise A promise
deleteActiveAccessTokens
Revoke all active access tokens
Parameters
optionsObject Options for this API call
Returns Promise A promise
deleteUser
Delete the current user
Parameters
optionsObject Options for this API call
Returns Promise A promise
trackingIdentity
Retrieves the information that is used to identify the current login for tracking.
Parameters
optionsObject? Options for this API call (optional, default{})options.fullBoolean? When true, retrieve all information for registering a user with the tracking API. When false,retrieve only the unique tracking ID for the current login. (optional, default `false`)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<Object> Resolve the tracking identify of the current login
listDevices
List devices claimed to the account or product
Parameters
optionsObject Options for this API calloptions.deviceIdString? (Product only) Filter results to devices with this ID (partial matching)options.deviceNameString? (Product only) Filter results to devices with this name (partial matching)options.groupsArray<string>? (Product only) A list of full group names to filter results to devices belonging to these groups only.options.sortAttrString? (Product only) The attribute by which to sort results. See API docs for options.options.sortDirString? (Product only) The direction of sorting. See API docs for options.options.pageNumber? (Product only) Current page of resultsoptions.perPageNumber? (Product only) Records per pageoptions.productString? List devices in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getDevice
Get detailed informationa about a device
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.productString? Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
claimDevice
Claim a device to the account. The device must be online and unclaimed.
Parameters
optionsObject Options for this API calloptions.deviceIdString Device IDoptions.requestTransferboolean True to request the device be transfered from another useroptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
addDeviceToProduct
Add a device to a product or move device out of quarantine.
Parameters
optionsObject Options for this API calloptions.deviceIdString Device IDoptions.productString Add to this product ID or slugoptions.fileObject A file that contains a single-column list of device IDs, device serial numbers, device IMEIs, or devie ICCIDs.Node: Either a path or Buffer. Browser: a File or Blob.options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
removeDevice
Unclaim / Remove a device from your account or product, or deny quarantine
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.denyBoolean? (Product only) Deny this quarantined device, instead of removing an already approved deviceoptions.productString Remove from this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
removeDeviceOwner
Unclaim a product device its the owner, but keep it in the product
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.productString Remove from this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
renameDevice
Rename a device
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.nameString Desired Nameoptions.productString? Rename device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
signalDevice
Instruct the device to turn on/off the LED in a rainbow pattern
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.signalBoolean Signal on or offoptions.productString? Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
setDeviceNotes
Store some notes about device
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.notesString Your notes about this deviceoptions.productString? Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
markAsDevelopmentDevice
Mark device as being used in development of a product so it opts out of automatic firmware updates
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.developmentBoolean Set to true to mark as development, false to return to product fleet (optional, defaulttrue)options.productString Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
lockDeviceProductFirmware
Mark device as being used in development of a product, so it opts out of automatic firmware updates
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.desiredFirmwareVersionNumber Lock the product device to run this firmware version.options.flashBoolean? Immediately flash firmware indicated by desiredFirmwareVersionoptions.productString Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
unlockDeviceProductFirmware
Mark device as receiving automatic firmware updates
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.productString Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
updateDevice
Update multiple device attributes at the same time
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.nameString? Desired Nameoptions.signalBoolean? Signal device on or offoptions.notesString? Your notes about this deviceoptions.developmentBoolean? (Product only) Set to true to mark as development, false to return to product fleetoptions.desiredFirmwareVersion(Number | null)? (Product only) Lock the product device to run this firmware version.Pass `null` to unlock firmware and go back to released firmware.options.flashBoolean? (Product only) Immediately flash firmware indicated by desiredFirmwareVersionoptions.productString? Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
unprotectDevice
Disable device protection.
Parameters
optionsObject Options for this API call.options.deviceIdString Device ID or name.options.orgString? Organziation ID or slug.options.productString? Product ID or slug.options.actionString Request action:prepareorconfirm.options.serverNonceString? Base64-encoded server nonce. Mandatory ifactionisconfirm,options.deviceNonceString? Base64-encoded device nonce. Mandatory ifactionisconfirm,options.deviceSignatureString? Base64-encoded device signature. Mandatory ifactionisconfirm,options.devicePublicKeyFingerprintString? Base64-encoded fingerprint of the device public key.Mandatory if `action` is `confirm`,options.authstring? The access token. Can be ignored if provided in constructor.options.headersObject? Key/value pairs to send as headers.options.contextObject? Request context.
Returns Promise A promise
provisionDevice
Provision a new device for products that allow self-provisioning
Parameters
optionsObject Options for this API call
Returns Promise A promise
getClaimCode
Generate a claim code to use in the device claiming process. To generate a claim code for a product, the access token MUST belong to a customer of the product.
Parameters
optionsObject Options for this API calloptions.iccidString? ICCID of the SIM card used in the Electronoptions.productString? Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getVariable
Get the value of a device variable
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.nameString Variable nameoptions.productString? Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
flashDevice
Compile and flash application firmware to a device. Pass a pre-compiled binary to flash it directly to the device.
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.productString Flash device in this product ID or slugoptions.filesObject Object containing files to be compiled and flashed. Keys should be the filenames, including relative path, and the values should be a path or Buffer of the file contents in Node, or a File or Blob in the browser.options.targetVersionString System firmware version to compile against (optional, defaultlatest)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
flashTinker
DEPRECATED: Flash the Tinker application to a device. Instead compile and flash the Tinker source code.
Parameters
optionsObject Options for this API call
Returns Promise A promise
compileCode
Compile firmware using the Particle Cloud
Parameters
optionsObject Options for this API calloptions.filesObject Object containing files to be compiled. Keys should be the filenames, including relative path, and the values should be a path or Buffer of the file contents in Node, or a File or Blob in the browser.options.platformIdNumber? Platform id number of the device you are compiling for. Common values are 0=Core, 6=Photon, 10=Electron.options.targetVersionString System firmware version to compile against (optional, defaultlatest)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
downloadFirmwareBinary
Download a firmware binary
Parameters
optionsObject Options for this API call
Returns Promise<RequestResponse, RequestError> A promise
sendPublicKey
Send a new device public key to the Particle Cloud
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.key(String | Buffer) Public key contentsoptions.algorithmString Algorithm used to generate the public key. Valid values arersaorecc. (optional, defaultrsa)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
callFunction
Call a device function
Parameters
optionsObject Options for this API calloptions.deviceIdString Device ID or Nameoptions.nameString Function nameoptions.argumentString Function argumentoptions.productString? Device in this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getEventStream
Get a stream of events
Parameters
optionsObject Options for this API call
Returns Promise If the promise resolves, the resolution value will be an EventStream object that will emit 'event' events.
publishEvent
Publish a event to the Particle Cloud
Parameters
optionsObject Options for this API calloptions.nameString Event nameoptions.dataString Event dataoptions.isPrivateBoolean Should the event be publicly available?options.productString? Event for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
Hook
Type: Object
Parameters
$0Object$0.event$0.url$0.device$0.rejectUnauthorized$0.noDefaults$0.hook$0.product$0.auth$0.headers$0.context
Properties
methodString? Type of web request triggered by the Webhook (GET, POST, PUT, or DELETE)authObject? Auth data like{ user: 'me', pass: '1234' }for basic auth or{ bearer: 'token' }to send with the Webhook requestheadersObject? Additional headers to add to the Webhook like{ 'X-ONE': '1', X-TWO: '2' }queryObject? Query params to add to the Webhook request like{ foo: 'foo', bar: 'bar' }jsonObject? JSON data to send with the Webhook request - setsContent-Typetoapplication/jsonformObject? Form data to send with the Webhook request - setsContent-Typetoapplication/x-www-form-urlencodedbodyString? Custom body to send with the Webhook requestresponseTemplateObject? Template to use to customize the Webhook response bodyresponseEventObject? The Webhook response event name that your devices can subscribe toerrorResponseEventObject? The Webhook error response event name that your devices can subscribe to
createWebhook
Create a webhook
Parameters
optionsObject Options for this API calloptions.eventString The name of the Particle event that should trigger the Webhookoptions.urlString The web address that will be targeted when the Webhook is triggeredoptions.deviceString? Trigger Webhook only for this device ID or Nameoptions.rejectUnauthorizedBoolean? Set tofalseto skip SSL certificate validation of the target URLoptions.noDefaultsBoolean? Don't include default event data in the webhook requestoptions.hookHook? Webhook configuration settingsoptions.productString? Webhook for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
deleteWebhook
Delete a webhook
Parameters
optionsObject Options for this API calloptions.hookIdString Webhook IDoptions.productString? Webhook for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
listWebhooks
List all webhooks owned by the account or product
Parameters
optionsObject Options for this API call
Returns Promise A promise
createIntegration
Create an integration to send events to an external service
See the API docs for details https://docs.particle.io/reference/api/#integrations-webhooks-
Parameters
optionsObject Options for this API calloptions.eventString Event that triggers the integrationoptions.settingsObject Settings specific to that integration typeoptions.deviceIdString? Trigger integration only for this device ID or Nameoptions.productString? Integration for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
editIntegration
Edit an integration to send events to an external service
See the API docs for details https://docs.particle.io/reference/api/#integrations-webhooks-
Parameters
optionsObject Options for this API calloptions.integrationIdString The integration to editoptions.eventString? Change the event that triggers the integrationoptions.settingsObject? Change the settings specific to that integration typeoptions.deviceIdString? Trigger integration only for this device ID or Nameoptions.productString? Integration for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
deleteIntegration
Delete an integration to send events to an external service
Parameters
optionsObject Options for this API calloptions.integrationIdString The integration to removeoptions.productString? Integration for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
listIntegrations
List all integrations owned by the account or product
Parameters
optionsObject Options for this API call
Returns Promise A promise
getUserInfo
Get details about the current user
Parameters
optionsObject Options for this API call
Returns Promise A promise
setUserInfo
Set details on the current user
Parameters
optionsObject Options for this API calloptions.accountInfoString Set user's extended info fields (name, business account, company name, etc)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
changeUsername
Change username (i.e, email)
Parameters
optionsObject Options for this API calloptions.currentPasswordString Current passwordoptions.usernameString New emailoptions.invalidateTokensBoolean Should all tokens be invalidated (optional, defaultfalse)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
changeUserPassword
Change user's password
Parameters
optionsObject Options for this API calloptions.currentPasswordString Current passwordoptions.passwordString New passwordoptions.invalidateTokensBoolean Should all tokens be invalidated (optional, defaultfalse)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
listSIMs
List SIM cards owned by a user or product
Parameters
optionsObject Options for this API calloptions.iccidString? (Product only) Filter to SIM cards matching this ICCIDoptions.deviceIdString? (Product only) Filter to SIM cards matching this device IDoptions.deviceNameString? (Product only) Filter to SIM cards matching this device nameoptions.pageNumber? (Product only) Current page of resultsoptions.perPageNumber? (Product only) Records per pageoptions.productString? SIM cards for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getSIMDataUsage
Get data usage for one SIM card for the current billing period
Parameters
optionsObject Options for this API calloptions.iccidString ICCID of the SIM cardoptions.productString? SIM card for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getFleetDataUsage
Get data usage for all SIM cards in a product the current billing period
Parameters
optionsObject Options for this API call
Returns Promise A promise
checkSIM
Check SIM status
Parameters
optionsObject Options for this API call
Returns Promise A promise
activateSIM
Activate and add SIM cards to an account or product
Parameters
optionsObject Options for this API calloptions.iccidString ICCID of the SIM cardoptions.iccidsArray<String> (Product only) ICCID of multiple SIM cards to importoptions.countryString The ISO country code for the SIM cardsoptions.promoCodeany?options.productString? SIM cards for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
deactivateSIM
Deactivate a SIM card so it doesn't incur data usage in future months.
Parameters
optionsObject Options for this API calloptions.iccidString ICCID of the SIM cardoptions.productString? SIM cards for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
reactivateSIM
Reactivate a SIM card the was deactivated or unpause a SIM card that was automatically paused
Parameters
optionsObject Options for this API calloptions.iccidString ICCID of the SIM cardoptions.mbLimitNumber? New monthly data limit. Necessary if unpausing a SIM cardoptions.productString? SIM cards for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
updateSIM
Update SIM card data limit
Parameters
optionsObject Options for this API calloptions.iccidString ICCID of the SIM cardoptions.mbLimitArray Data limit in megabyte for the SIM cardoptions.productString? SIM cards for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
removeSIM
Remove a SIM card from an account so it can be activated by a different account
Parameters
optionsObject Options for this API calloptions.iccidString ICCID of the SIM cardoptions.productString? SIM cards for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
listBuildTargets
List valid build targets to be used for compiling
Parameters
optionsObject Options for this API calloptions.onlyFeaturedBoolean Only list featured build targets (optional, defaultfalse)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
listLibraries
List firmware libraries
Parameters
optionsObject Options for this API calloptions.pageNumber Page index (default, first page)options.limitNumber Number of items per pageoptions.filterString Search term for the librariesoptions.sortString Ordering key for the library listoptions.architecturesArray<String> List of architectures to filteroptions.categoryString Category to filteroptions.scopeString The library scope to list. Default is 'all'. Other values are\- 'all' - list public libraries and my private libraries \- 'public' - list only public libraries \- 'private' - list only my private libraries \- 'mine' - list my libraries (public and private) \- 'official' - list only official libraries \- 'verified' - list only verified libraries \- 'featured' - list only featured librariesoptions.excludeScopesString list of scopes to excludeoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getLibrary
Get firmware library details
Parameters
optionsObject Options for this API calloptions.nameString Name of the library to fetchoptions.versionString Version of the library to fetch (default: latest)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getLibraryVersions
Firmware library details for each version
Parameters
optionsObject Options for this API calloptions.nameString Name of the library to fetchoptions.pageNumber Page index (default, first page)options.limitNumber Number of items per pageoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
contributeLibrary
Contribute a new library version from a compressed archive
Parameters
optionsObject Options for this API calloptions.archive(String | Buffer) Compressed archive file containing the library sourcesEither a path or Buffer of the file contents in Node, or a File or Blob in the browser.options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
publishLibrary
Publish the latest version of a library to the public
Parameters
optionsObject Options for this API call
Returns Promise A promise
deleteLibrary
Delete one version of a library or an entire private library
Parameters
optionsObject Options for this API calloptions.nameString Name of the library to removeoptions.forceString Key to force deleting a public libraryoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
downloadFile
Download an external file that may not be on the API
Parameters
optionsObject Options for this API call
Returns Promise Resolves to a buffer with the file data
listOAuthClients
List OAuth client created by the account
Parameters
optionsObject Options for this API call
Returns Promise A promise
createOAuthClient
Create an OAuth client
Parameters
optionsObject Options for this API calloptions.nameString Name of the OAuth clientoptions.typeString web, installed or weboptions.redirect_uriString? URL to redirect after OAuth flow. Only for type web.options.scopeObject? Limits what the access tokens created by this client can do.options.productString? Create client for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
updateOAuthClient
Update an OAuth client
Parameters
optionsObject Options for this API calloptions.clientIdString The OAuth client to updateoptions.nameString? New Name of the OAuth clientoptions.scopeObject? New scope of the OAuth clientoptions.productString? Update client linked to this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
deleteOAuthClient
Delete an OAuth client
Parameters
optionsObject Options for this API calloptions.clientIdString The OAuth client to updateoptions.productString? OAuth client linked to this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
listProducts
List products the account has access to
Parameters
optionsObject Options for this API call
Returns Promise A promise
getProduct
Get detailed information about a product
Parameters
optionsObject Options for this API call
Returns Promise A promise
listProductFirmware
List product firmware versions
Parameters
optionsObject Options for this API call
Returns Promise A promise
uploadProductFirmware
List product firmware versions
Parameters
optionsObject Options for this API calloptions.fileObject Path or Buffer of the new firmware fileEither a path or Buffer of the file contents in Node, or a File or Blob in the browser.options.versionNumber Version number of new firmwareoptions.titleString Short identifier for the new firmwareoptions.descriptionString? Longer description for the new firmwareoptions.productString Firmware for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getProductFirmware
Get information about a product firmware version
Parameters
optionsObject Options for this API calloptions.versionNumber Version number of firmwareoptions.productString Firmware for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
updateProductFirmware
Update information for a product firmware version
Parameters
optionsObject Options for this API calloptions.versionNumber Version number of new firmwareoptions.titleString? New titleoptions.descriptionString? New descriptionoptions.productString Firmware for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
downloadProductFirmware
Download a product firmware binary
Parameters
optionsObject Options for this API calloptions.versionNumber Version number of new firmwareoptions.productString Firmware for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse, RequestError> A promise that resolves with either the requested data or an error object
releaseProductFirmware
Release a product firmware version as the default version
Parameters
optionsObject Options for this API calloptions.versionNumber Version number of new firmwareoptions.productString Firmware for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
listTeamMembers
List product team members
Parameters
optionsObject Options for this API call
Returns Promise A promise
inviteTeamMember
Invite Particle user to a product team
Parameters
optionsObject Options for this API calloptions.usernameString Username for the Particle accountoptions.productString Team for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
removeTeamMember
Remove Particle user to a product team
Parameters
optionsObject Options for this API calloptions.usernameString Username for the Particle accountoptions.productString Team for this product ID or slugoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
lookupSerialNumber
Fetch details about a serial number
Parameters
optionsObject Options for this API calloptions.serialNumberString The serial number printed on the barcode of the device packagingoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
createMeshNetwork
Create a mesh network
Parameters
optionsObject Options for this API calloptions.nameString Network nameoptions.deviceIdString Gateway device IDoptions.iccidString? ICCID of the active SIM card (only for cellular gateway devices)options.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<Object> A promise
removeMeshNetwork
Remove a mesh network.
Parameters
optionsObject Options for this API call
Returns Promise<Object> A promise
listMeshNetworks
List all mesh networks
Parameters
optionsObject Options for this API calloptions.pageNumber? Current page of resultsoptions.perPageNumber? Records per pageoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<Object> A promise
getMeshNetwork
Get information about a mesh network.
Parameters
optionsObject Options for this API call
Returns Promise<Object> A promise
updateMeshNetwork
Modify a mesh network.
Parameters
optionsObject Options for this API calloptions.networkIdString Network ID or nameoptions.actionString 'add-device', 'remove-device', 'gateway-enable' or 'gateway-disable'options.deviceIdString Device IDoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<Object> A promise
addMeshNetworkDevice
Add a device to a mesh network.
Parameters
optionsObject Options for this API call
Returns Promise<Object> A promise
removeMeshNetworkDevice
Remove a device from a mesh network.
Parameters
optionsObject Options for this API call
Returns Promise<Object> A promise
listMeshNetworkDevices
List all devices of a mesh network.
Parameters
optionsObject Options for this API calloptions.networkIdString Network ID or nameoptions.roleNumber? Device role: 'gateway' or 'node'options.pageNumber? Current page of resultsoptions.perPageNumber? Records per pageoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<Object> A promise
getProductConfiguration
Get product configuration
Parameters
optionsObject Options for this API call
Returns Promise A promise
getProductConfigurationSchema
Get product configuration schema
Parameters
optionsObject Options for this API call
Returns Promise A promise
getProductDeviceConfiguration
Get product device's configuration
Parameters
optionsObject Options for this API calloptions.authstring? The access token. Can be ignored if provided in constructoroptions.productString Config for this product ID or slugoptions.deviceIdString Device ID to accessoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getProductDeviceConfigurationSchema
Get product device's configuration schema
Parameters
optionsObject Options for this API calloptions.authstring? The access token. Can be ignored if provided in constructoroptions.productString Config for this product ID or slugoptions.deviceIdString Device ID to accessoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
setProductConfiguration
Set product configuration
Parameters
optionsObject Options for this API calloptions.authstring? The access token. Can be ignored if provided in constructoroptions.productString Config for this product ID or slugoptions.configObject Product configuration to updateoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
setProductDeviceConfiguration
Set product configuration for a specific device within the product
Parameters
optionsObject Options for this API calloptions.authstring? The access token. Can be ignored if provided in constructoroptions.productString Config for this product ID or slugoptions.deviceIdString Device ID to accessoptions.configObject Product configuration to updateoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getProductLocations
Query location for devices within a product
Parameters
optionsObject Options for this API calloptions.authstring? The access token. Can be ignored if provided in constructoroptions.productString Locations for this product ID or slugoptions.dateRangeString Start and end date in ISO8601 format, separated by comma, to queryoptions.rectBlString Bottom left of the rectangular bounding box to query. Latitude and longitude separated by commaoptions.rectTrString Top right of the rectangular bounding box to query. Latitude and longitude separated by commaoptions.deviceIdString Device ID prefix to include in the queryoptions.deviceNameString Device name prefix to include in the queryoptions.groupsString Array of group names to include in the queryoptions.pageString Page of results to display. Defaults to 1options.perPageString Number of results per page. Defaults to 20. Maximum of 100options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
getProductDeviceLocations
Query location for one device within a product
Parameters
optionsObject Options for this API calloptions.authstring? The access token. Can be ignored if provided in constructoroptions.productString Locations for this product ID or slugoptions.dateRangeString Start and end date in ISO8601 format, separated by comma, to queryoptions.rectBlString Bottom left of the rectangular bounding box to query. Latitude and longitude separated by commaoptions.rectTrString Top right of the rectangular bounding box to query. Latitude and longitude separated by commaoptions.deviceIdString Device ID to queryoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise A promise
executeLogic
Executes the provided logic function once and returns the result. No logs, runs, etc are saved
NOTE: Any external interactions such as Particle.publish will actually occur when the logic is executed.
Parameters
optionsObject The options for creating the logic function.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.logicObject The logic "function" which will be executed onceoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the created logic function data.
createLogicFunction
Creates a new logic function in the specified organization or sandbox using the provided function data.
When you create a logic function with Event logic triggers, events will immediately start being handled by the function code.
When you create a Scheduled logic trigger, it will immediately be scheduled at the next time according to the cron and start_at properties.
Parameters
optionsObject The options for creating the logic function.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.logicFunctionObject The logic function object containing the function details.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the created logic function data.
getLogicFunction
Get a logic function in the specified organization or sandbox by logic function ID.
Parameters
optionsObject The options for the logic function.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.logicFunctionIdstring The ID of the logic function to retrieve.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the specified logic function data.
updateLogicFunction
Updates an existing logic function in the specified organization or sandbox using the provided function data.
If you include an id on a logic trigger, it will update the logic trigger in place.
Parameters
optionsObject The options for updating the logic function.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.logicFunctionIdstring The ID of the logic function to update.options.logicFunctionObject The logic function object containing the logic function details.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context.
Returns Promise<RequestResponse> A promise that resolves to the updated logic function data.
deleteLogicFunction
Deletes a logic function in the specified organization or sandbox by logic function ID.
Parameters
optionsObject The options for deleting the logic function.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.logicFunctionIdstring The ID of the logic function to delete.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context.
Returns Promise<RequestResponse> A promise that resolves to an object containing the deleted logic function ID.
listLogicFunctions
Lists all logic functions in the specified organization or sandbox.
Parameters
optionsObject The options for listing logic functions.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.todayStatsboolean? Whether to include today's stats in the responseoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context.
Returns Promise<RequestResponse> A promise that resolves to an array of logic functions data.
listLogicRuns
Lists all logic runs for the specified logic function in the specified organization or sandbox.
Parameters
optionsObject The options for the request.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.logicFunctionIdstring The ID of the logic function for which to retrieve the logic runs.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to an array of logic run data.
getLogicRun
Retrieves a logic run by its ID for the specified logic function in the specified organization or sandbox.
Parameters
optionsObject The options for the request.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.logicFunctionIdstring The ID of the logic function for which to retrieve the logic run.options.logicRunIdstring The ID of the logic run to retrieve.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to an array of logic run data for the specified logic run ID.
getLogicRunLogs
Retrieves the logs for a logic run by its ID for the specified logic function in the specified organization or sandbox.
Parameters
optionsObject The options for the request.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The unique identifier of the organization.options.logicFunctionIdstring The ID of the logic function for which to retrieve the logic run logs.options.logicRunIdstring The ID of the logic run for which to retrieve the logs.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the logs for the specified logic run ID.
createLedger
Creates a new ledger definition in the specified organization or sandbox.
Parameters
optionsObject The options for creating the ledger definition.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.ledgerobject The ledger definition object.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the created ledger definition data.
getLedger
Get a ledger definition in the specified organization or sandbox by ledger name.
Parameters
optionsObject The options for the ledger definition.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.ledgerNamestring The ID of the ledger definition to retrieve.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the specified ledger definition data.
updateLedger
Updates an existing ledger definition in the specified organization or sandbox.
Parameters
optionsObject The options for updating the ledger definition.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.ledgerNamestring Name of the ledger definition to update.options.ledgerobject The ledger definition object.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context.
Returns Promise<RequestResponse> A promise that resolves to the updated ledger definition data.
archiveLedger
Archives a ledger definition in the specified organization or sandbox by ledger name.
Parameters
optionsObject The options for archiving the ledger definition.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.ledgerNamestring Name of the ledger definition to archive.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context.
Returns Promise<RequestResponse> A promise that resolves to an object confirming the ledger definition was archived.
Scope
Type: ("Owner" | "Product" | "Device")
Parameters
$0Object$0.auth$0.org$0.scope$0.page$0.perPage$0.archived$0.headers$0.context
listLedgers
Lists all ledger definitions in the specified organization or sandbox.
Parameters
optionsObject The options for listing ledger definitions.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.scopeScope? Filter to show only ledgers of the specified scopeoptions.pagenumber? Page of results to displayoptions.perPagenumber? Number of results per page. Default is 100options.archivedboolean? Filter to show only archived ledger or non-archived ledgers. If not provided, all ledgers are returned.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context.
Returns Promise<RequestResponse> A promise that resolves to an array of ledger definition data.
getLedgerInstance
Get ledger instance data.
Parameters
optionsObject The options for the ledger instance.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.ledgerNamestring Ledger name.options.scopeValuestring Scope value.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the specified ledger instance data.
SetMode
Type: ("Replace" | "Merge")
Parameters
$0Object$0.auth$0.org$0.ledgerName$0.scopeValue$0.instance$0.setMode$0.headers$0.context
setLedgerInstance
Set ledger instance data.
Parameters
optionsObject The options for updating the ledger instance.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.ledgerNamestring Ledger name.options.scopeValuestring Scope value.options.instanceobject The instance with the dataoptions.setModeSetMode? How the data should be set with existing data. Default is "Replace"options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context.
Returns Promise<RequestResponse> A promise that resolves to the updated ledger instance data.
deleteLedgerInstance
Delete a ledger instance in the specified organization or sandbox by ledger name.
Parameters
optionsObject The options for archiving the ledger instance.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.ledgerNamestring Name of the ledger instance to archive.options.scopeValuestring Scope value.options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context.
Returns Promise<RequestResponse> A promise that resolves to an object confirming the ledger instance was deleted.
listLedgerInstances
Lists ledger instances in the specified organization or sandbox.
Parameters
optionsObject The options for listing ledger instances.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The unique identifier of the organization.options.ledgerNamestring Name of the ledger instance to archive.options.pagenumber? Page of results to displayoptions.perPagenumber? Number of results per page. Default is 100options.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context.
Returns Promise<RequestResponse> A promise that resolves to an array of ledger instance data.
listLedgerInstanceVersions
List ledger instance versions
Parameters
optionsObject The options for the ledger instance.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.ledgerNamestring Ledger name.options.scopeValuestring Scope value.options.replacedBeforestring? ISO date string to filter to instances replaced before this timeoptions.replacedAfterstring? ISO date string to filter to instances replaced after this timeoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to an array of ledger instance data.
getLedgerInstanceVersion
Get specific ledger instance version
Parameters
optionsObject The options for the ledger instance.options.authstring? The access token. Can be ignored if provided in constructoroptions.orgstring? The Organization ID or slug. If not provided, the request will go to your sandbox account.options.ledgerNamestring Ledger name.options.scopeValuestring Scope value.options.versionstring Version of the ledger instanceoptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the specified ledger instance data.
listDeviceOsVersions
List Device OS versions
Parameters
optionsObject Options for this API calloptions.platformIdNumber? Platform ID to filter Device OS versionsoptions.internalVersionNumber? Internal version number to filter Device OS versionsoptions.pageNumber? Page number for paginationoptions.perPageNumber? Number of items per pageoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the list of Device OS versions.
getDeviceOsVersion
Get a specific Device OS version
Parameters
optionsObject Options for this API calloptions.versionString Version of the Device OSoptions.platformIdNumber? Optional platform ID to filter Device OS versionoptions.authstring? The access token. Can be ignored if provided in constructoroptions.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.options.contextObject? Request context
Returns Promise<RequestResponse> A promise that resolves to the specified Device OS version data.
setDefaultAuth
Set default auth token that will be used in each method if auth is not provided
Parameters
authstring The access token
- Throws Error When not auth string is provided
get
Make a GET request
Parameters
paramsobjectparams.uristring The URI to requestparams.authstring? Authorization token to useparams.headersobject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.params.queryobject? Key/Value pairs of query params or a correctly formatted stringparams.contextobject? The invocation context, describing the tool and project
Returns Promise<RequestResponse, RequestError> A promise that resolves with either the requested data or an error object
head
Make a HEAD request
Parameters
paramsobjectparams.uristring The URI to requestparams.authstring? Authorization token to useparams.headersobject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.params.queryobject? Key/Value pairs of query params or a correctly formatted stringparams.contextobject? The invocation context, describing the tool and project
Returns Promise<RequestResponse, RequestError> A promise that resolves with either the requested data or an error object
post
Make a POST request
Parameters
paramsobjectparams.uristring The URI to requestparams.authstring? Authorization token to useparams.headersobject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.params.data(string | object)? Request bodyparams.contextobject? The invocation context, describing the tool and project
Returns Promise<RequestResponse, RequestError> A promise that resolves with either the requested data or an error object
put
Make a PUT request
Parameters
paramsobjectparams.uristring The URI to requestparams.authstring? Authorization token to useparams.headersobject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.params.data(string | object)? Request bodyparams.queryobject? Key/Value pairs of query params or a correctly formatted stringparams.contextobject? The invocation context, describing the tool and project
Returns Promise<RequestResponse, RequestError> A promise that resolves with either the requested data or an error object
delete
Make a DELETE request
Parameters
paramsobjectparams.uristring The URI to requestparams.authstring? Authorization token to useparams.headersobject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.params.data(string | object)? Request bodyparams.contextobject? The invocation context, describing the tool and project
Returns Promise<RequestResponse, RequestError> A promise that resolves with either the requested data or an error object
request
Parameters
argsObject An obj with all the possible request configurationsargs.uriString The URI to requestargs.methodString The method used to request the URI, should be in uppercase.args.headersObject? Key/Value pairs like{ 'X-FOO': 'foo', X-BAR: 'bar' }to send as headers.args.dataobject? Arbitrary data to send as the body.args.authstring? Authorizationargs.queryObject? Query parametersargs.formObject? Form fieldsargs.filesObject? Array of file names and file contentargs.contextObject? The invocation context, describing the tool and project.args.isBufferboolean? Indicate if the response should be treated as Buffer instead of JSON
Returns Promise<RequestResponse, RequestError> A promise that resolves with either the requested data or an error object