Skip to contentSkip to navigationSkip to topbar
On this page

Secret resource


You can provide configuration data for multiple Microvisor-empowered IoT devices using the Secret resource. Secrets are intended as a way to upload confidential data to the Twilio cloud so it need not be baked into application code. Instead, the application code running on the device retrieves the Secret when it needs the information.

Unlike Configs, Secrets' values cannot be accessed via the API once they have been created. The retrieval actions listed below will return Secrets' metadata, not their values.

Each Secret is a key:value pair which your application code can access using Microvisor System Calls.

Keys are text identifiers of up to 100 characters in length. They must be unique for a given account.

Values must also be supplied as text, of up to 4096 characters in length. If you wish to make binary data available to your devices, you will need to encode it as text before creating the Secret. For example, you might used base64 encoding. Your application must decode the value back to binary after acquiring it from the Twilio cloud.

Secret resources are accessed at this endpoint:

https://microvisor.twilio.com/v1/Secrets

Secret resources are accessible from all devices associated with an account. For Secrets that are made available to specific devices, please see Device Secrets.


Secret Properties

secret-properties page anchor
Property nameTypeRequiredDescriptionChild properties
keystringOptional
Not PII

The secret key; up to 100 characters.


date_rotatedstring<date-time>Optional

urlstring<uri>Optional

The absolute URL of the Secret.


Create an account-level Secret

create-an-account-level-secret page anchor
POST https://microvisor.twilio.com/v1/Secrets

Request body parameters

request-body-parameters page anchor
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Keystringrequired

The secret key; up to 100 characters.


Valuestringrequired

The secret value; up to 4096 characters.

Create an account-level SecretLink to code sample: Create an account-level Secret
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createAccountSecret() {
11
const accountSecret = await client.microvisor.v1.accountSecrets.create({
12
key: "key_name",
13
value: "value",
14
});
15
16
console.log(accountSecret.key);
17
}
18
19
createAccountSecret();

Output

1
{
2
"key": "key_name",
3
"date_rotated": "2021-01-01T12:34:56Z",
4
"url": "https://microvisor.twilio.com/v1/Secrets/first"
5
}

Retrieve an account-level Secret's metadata

retrieve-an-account-level-secrets-metadata page anchor
GET https://microvisor.twilio.com/v1/Secrets/{Key}

Property nameTypeRequiredPIIDescription
Keystringrequired

The secret key; up to 100 characters.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchAccountSecret() {
11
const accountSecret = await client.microvisor.v1
12
.accountSecrets("Key_name")
13
.fetch();
14
15
console.log(accountSecret.key);
16
}
17
18
fetchAccountSecret();

Output

1
{
2
"key": "Key_name",
3
"date_rotated": "2021-01-01T12:34:57Z",
4
"url": "https://microvisor.twilio.com/v1/Secrets/first"
5
}

Delete an account-level Secret

delete-an-account-level-secret page anchor
DELETE https://microvisor.twilio.com/v1/Secrets/{Key}

Property nameTypeRequiredPIIDescription
Keystringrequired

The secret key; up to 100 characters.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function deleteAccountSecret() {
11
await client.microvisor.v1.accountSecrets("key_name").remove();
12
}
13
14
deleteAccountSecret();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.