How it works
This Scriptable helper prompts you for a Key Name and a Secret Value, then stores the value securely using Scriptable’s Keychain. It’s perfect for Canvas API workflows where you don’t want tokens hardcoded into your scripts.
Security note: This script does not print your secret value to the console.
Recommended key names
- BASE_URL — Your Canvas base URL
- API_TOKEN — Your Canvas API token
Copy + paste script
Click the button to copy the entire script. Then paste it into Scriptable and run it once to save your values.
// ------------------------------------------------------------
// Scriptable Keychain Helper
// Canvas on Tap Freebie Script
// ------------------------------------------------------------
// This script prompts the user for a Keychain key name and value,
// then securely stores the value using Scriptable's Keychain API.
//
// Example use cases:
// - Storing an API token
// - Saving a Canvas API URL
// - Saving a personal access key
//
// Notes:
// - Keychain values are stored securely on the device.
// - If the key already exists, this script will overwrite it.
// ------------------------------------------------------------
const keychainAlert = new Alert();
keychainAlert.title = "Save Keychain Secret";
keychainAlert.message =
"Enter a key name and a secret value to store securely in Scriptable's Keychain.";
// Input fields
keychainAlert.addTextField("Key Name (example: API_TOKEN)", "");
keychainAlert.addTextField("Secret Value (example: 123abc...)", "");
// Buttons
keychainAlert.addAction("Save Secret");
keychainAlert.addCancelAction("Cancel");
// Show alert
const buttonIndex = await keychainAlert.present();
// If user cancels, Scriptable returns -1
if (buttonIndex === -1) {
console.log("Cancelled. No Keychain value was saved.");
Script.complete();
}
// Get user input
const secretKeyName = keychainAlert.textFieldValue(0).trim();
const secretValue = keychainAlert.textFieldValue(1).trim();
// Validate input
if (!secretKeyName || !secretValue) {
console.log("Error: Both the key name and secret value are required.");
Script.complete();
}
// Save to Scriptable Keychain
Keychain.set(secretKeyName, secretValue);
// Confirmation output (DO NOT print secretValue for security)
console.log("Saved Keychain value successfully.");
console.log(`Key Name: ${secretKeyName}`);
Next step: use your saved secret
Once you’ve saved a value (example: canvasApiToken), you can retrieve it in any script like this:
const token = Keychain.get("canvasApiToken");
// Use token in your request headers
If you’re building a reusable makeRequest helper, pull your token once at the top of the script and reuse it across calls.