diff --git a/.optimize-cache.json b/.optimize-cache.json index 6ef84c3f1a..86e77c00e0 100644 --- a/.optimize-cache.json +++ b/.optimize-cache.json @@ -1331,7 +1331,9 @@ "images/docs/databases/scale-policies.png": "549c929932a92902c6a17684730a4bffe0c52ed8dd3d9bebc7ecc7818c81f244", "images/docs/dev-keys/dark.png": "137a92c18e9dfb2c000dea70d7fea09895abe2b46a69bdf8b736997e21c457ba", "images/docs/dev-keys/light.png": "7737135bb6c721adad6761d6c00616d3e9f5a88f153c8481ca55cdf481d63c42", + "images/docs/functions/dark/env-variables.png": "0fe62180f8b3b96f7944c91afcc87dda42cf52d8ce10672608c1df009b048b42", "images/docs/functions/dark/template.png": "4149a261979cb36cf74309d1836a3fcd926f2d33587e92080d541ffcbc3ad19c", + "images/docs/functions/env-variables.png": "003c18ef56a95f0784c9ffd609e313955bd83b61ef277c454bb7dd5b2192280b", "images/docs/functions/execution/dark/execute-function.png": "69063c276041e1e8cea09fb7aa27d3df6727fa6806d15101ac291e1b51f14344", "images/docs/functions/execution/dark/scheduled-execution-function.png": "19fd1f34644186c0113f060c4f4b9c42ecd8392e8a86f32df44f90086943ba33", "images/docs/functions/execution/execute-function.png": "9a5abab51d8c144214ecb6ff13ddd9d60c2cfcc7783aa2946aca5256f4bb83d5", @@ -1443,7 +1445,9 @@ "images/docs/platform/dark/add-platform.png": "1bb0e7dba22556e64064951882d625532285fa80bed43fd77774f31545a15b0f", "images/docs/platform/dark/create-api-key.png": "f15696f0b28dfc46813d7185be11da8be89da72be66b1894cfcc7227036e4afa", "images/docs/platform/dark/create-webhook.png": "88f7f5c857fe986b5803c7df003c4db55faa79e3fa3135cf9491073d0b2736be", + "images/docs/platform/dark/env-variables.png": "da2a73b5d3420063e9869c40050b6168e5b5446a97772a26ca2a894e36021134", "images/docs/platform/dark/execution-details.png": "c0481ddc206447460f9d317ba8d421615066f67a50bc9ef41a8f71766ecffb14", + "images/docs/platform/env-variables.png": "16f95151e4f6ee9fb8056f075b9f5027fd91f0c2a28586c5624c3ffe9b7a1ee8", "images/docs/platform/execution-details.png": "ece1364b8b00254bbd982421b6eed6d7f519d34c4e80377fcaaa4cb5d5dd3f89", "images/docs/quick-starts/add-platform.png": "3b13ba983ea1d2529a1f34a719acef903ec0b58879ed511012280a28ccbde17e", "images/docs/quick-starts/create-project.png": "7fdb25def02c5dbdb08cd38c2d03b7b454c930194a900553e3e68d51cb28a1d5", diff --git a/src/partials/functions-env-vars.md b/src/partials/functions-env-vars.md new file mode 100644 index 0000000000..1c5bcde396 --- /dev/null +++ b/src/partials/functions-env-vars.md @@ -0,0 +1,14 @@ +| Variable | Description | Available at Build and/or Run Time | +| ----------------------------------- | ---------------------------------------------------------- | ---------------------------------- | +| `APPWRITE_FUNCTION_API_ENDPOINT` | The API endpoint of the running function | Both | +| `APPWRITE_VERSION` | The Appwrite version used to run the function | Both | +| `APPWRITE_REGION` | The region where the function will run from | Both | +| `APPWRITE_FUNCTION_API_KEY` | The function API key used for server authentication | Build time | +| `APPWRITE_FUNCTION_ID` | The ID of the running function | Both | +| `APPWRITE_FUNCTION_NAME` | The name of the running function | Both | +| `APPWRITE_FUNCTION_DEPLOYMENT` | The deployment ID of the running function | Both | +| `APPWRITE_FUNCTION_PROJECT_ID` | The project ID of the running function | Both | +| `APPWRITE_FUNCTION_RUNTIME_NAME` | The runtime of the running function | Both | +| `APPWRITE_FUNCTION_RUNTIME_VERSION` | The runtime version of the running function | Both | +| `APPWRITE_FUNCTION_CPUS` | The CPU (runtime) specification of the running function | Both | +| `APPWRITE_FUNCTION_MEMORY` | The memory (runtime) specification of the running function | Both | diff --git a/src/routes/blog/post/announcing-variables-api/+page.markdoc b/src/routes/blog/post/announcing-variables-api/+page.markdoc new file mode 100644 index 0000000000..0ffba96002 --- /dev/null +++ b/src/routes/blog/post/announcing-variables-api/+page.markdoc @@ -0,0 +1,1259 @@ +--- +layout: post +title: "Announcing the Variables API: Manage function, site, and project variables from your Server SDKs" +description: Environment variables for functions, sites, and projects can now be created, updated, and deleted programmatically through the Appwrite Server SDKs. Provision configuration as code, rotate secrets in scripts, and bootstrap new environments without touching the Console. +date: 2026-04-28 +cover: /images/blog/announcing-variables-api/cover.png +timeToRead: 4 +author: matej-baco +category: announcement +featured: false +callToAction: true +--- + +Environment variables have always been part of Appwrite. You could set them on a function, on a site, or on the project as a whole, and your code would pick them up at build and runtime. The catch was that all of this lived inside the Appwrite Console. If you wanted to provision configuration as part of a script, rotate a secret across environments, or bootstrap a new project from a template, you had to click through the UI. + +Today, we are announcing the **Variables API**, a unified set of endpoints for managing environment variables on functions, sites, and projects programmatically through the Appwrite Server SDKs. + +This is part of a wider effort to make everything in Appwrite accessible through the API. Anything you can do in the Console should be doable from code, and variables are now a first-class part of that surface. + +# Why this matters + +Configuration drift, manual secret rotation, and click-ops bootstrapping are some of the easiest ways to break a production environment. The Variables API removes them from the loop: + +- **Provision configuration as code** as part of CI/CD, infrastructure scripts, or project templates. +- **Rotate secrets across environments** without opening the Console for each function, site, and project. +- **Bootstrap new projects** with the same baseline of variables every time. +- **Build internal tooling** that lets your team manage shared configuration in one place. +- **Audit and reconcile** what is set against what should be set, programmatically. + +# Three scopes, one API surface + +The Variables API covers all three scopes Appwrite already supported in the Console: + +- **Function variables** live on a single function and are set on the `Functions` service. +- **Site variables** live on a single site and are set on the `Sites` service. +- **Project variables** are shared across every function and site in the project and are set on the `Project` service. + +Each scope exposes the same five operations: create, list, get, update, and delete. At build and runtime, project variables load first, function or site variables override matching keys, and Appwrite-injected variables (those prefixed with `APPWRITE_`) take final precedence. + +# How it works + +The relevant API key scopes are: + +- **`functions.read`** / **`functions.write`** for function variables +- **`sites.read`** / **`sites.write`** for site variables +- **`project.read`** / **`project.write`** for project variables + +## Create a project variable + +The new `Project` service exposes `createVariable` for shared configuration: + +{% multicode %} +```server-nodejs +import { Client, Project, ID } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.createVariable({ + variableId: ID.unique(), + key: 'STRIPE_KEY', + value: 'sk_live_...', + secret: true // optional +}); +``` +```server-deno +import { Client, Project, ID } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.createVariable({ + variableId: ID.unique(), + key: 'STRIPE_KEY', + value: 'sk_live_...', + secret: true // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$project = new Project($client); + +$result = $project->createVariable( + variableId: ID::unique(), + key: 'STRIPE_KEY', + value: 'sk_live_...', + secret: true // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.id import ID +from appwrite.services.project import Project +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +project = Project(client) + +result: Variable = project.create_variable( + variable_id = ID.unique(), + key = 'STRIPE_KEY', + value = 'sk_live_...', + secret = True # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +project = Project.new(client) + +result = project.create_variable( + variable_id: ID.unique(), + key: 'STRIPE_KEY', + value: 'sk_live_...', + secret: true # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Project project = new Project(client); + +Variable result = await project.CreateVariable( + variableId: ID.Unique(), + key: "STRIPE_KEY", + value: "sk_live_...", + secret: true // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Project project = Project(client); + +Variable result = await project.createVariable( + variableId: ID.unique(), + key: 'STRIPE_KEY', + value: 'sk_live_...', + secret: true, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.ID +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Project + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val project = Project(client) + +val response = project.createVariable( + variableId = ID.unique(), + key = "STRIPE_KEY", + value = "sk_live_...", + secret = true // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.ID; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Project; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Project project = new Project(client); + +project.createVariable( + ID.unique(), // variableId + "STRIPE_KEY", // key + "sk_live_...", // value + true, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let project = Project(client) + +let variable = try await project.createVariable( + variableId: ID.unique(), + key: "STRIPE_KEY", + value: "sk_live_...", + secret: true // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" + "github.com/appwrite/sdk-for-go/id" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +project := appwrite.NewProject(client) + +response, error := project.CreateVariable( + id.Unique(), + "STRIPE_KEY", + "sk_live_...", + appwrite.WithCreateVariableSecret(true), +) +``` +```server-rust +use appwrite::Client; +use appwrite::id::ID; +use appwrite::services::Project; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let project = Project::new(&client); + + let result = project.create_variable( + &ID::unique(), + "STRIPE_KEY", + "sk_live_...", + Some(true) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Create a function variable + +The same shape applies on the `Functions` service for variables scoped to a single function: + +{% multicode %} +```server-nodejs +import { Client, Functions } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.createVariable({ + functionId: '', + key: 'OPENAI_API_KEY', + value: 'sk-...', + secret: true // optional +}); +``` +```server-deno +import { Client, Functions } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.createVariable({ + functionId: '', + key: 'OPENAI_API_KEY', + value: 'sk-...', + secret: true // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$functions = new Functions($client); + +$result = $functions->createVariable( + functionId: '', + key: 'OPENAI_API_KEY', + value: 'sk-...', + secret: true // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.functions import Functions +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +functions = Functions(client) + +result: Variable = functions.create_variable( + function_id = '', + key = 'OPENAI_API_KEY', + value = 'sk-...', + secret = True # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +functions = Functions.new(client) + +result = functions.create_variable( + function_id: '', + key: 'OPENAI_API_KEY', + value: 'sk-...', + secret: true # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Functions functions = new Functions(client); + +Variable result = await functions.CreateVariable( + functionId: "", + key: "OPENAI_API_KEY", + value: "sk-...", + secret: true // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Functions functions = Functions(client); + +Variable result = await functions.createVariable( + functionId: '', + key: 'OPENAI_API_KEY', + value: 'sk-...', + secret: true, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Functions + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val functions = Functions(client) + +val response = functions.createVariable( + functionId = "", + key = "OPENAI_API_KEY", + value = "sk-...", + secret = true // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Functions; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Functions functions = new Functions(client); + +functions.createVariable( + "", // functionId + "OPENAI_API_KEY", // key + "sk-...", // value + true, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let functions = Functions(client) + +let variable = try await functions.createVariable( + functionId: "", + key: "OPENAI_API_KEY", + value: "sk-...", + secret: true // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +functions := appwrite.NewFunctions(client) + +response, error := functions.CreateVariable( + "", + "OPENAI_API_KEY", + "sk-...", + appwrite.WithCreateVariableSecret(true), +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Functions; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let functions = Functions::new(&client); + + let result = functions.create_variable( + "", + "OPENAI_API_KEY", + "sk-...", + Some(true) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Create a site variable + +And on the `Sites` service for variables scoped to a single site: + +{% multicode %} +```server-nodejs +import { Client, Sites } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.createVariable({ + siteId: '', + key: 'NEXT_PUBLIC_ANALYTICS_ID', + value: 'G-XXXXXXX', + secret: false // optional +}); +``` +```server-deno +import { Client, Sites } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.createVariable({ + siteId: '', + key: 'NEXT_PUBLIC_ANALYTICS_ID', + value: 'G-XXXXXXX', + secret: false // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$sites = new Sites($client); + +$result = $sites->createVariable( + siteId: '', + key: 'NEXT_PUBLIC_ANALYTICS_ID', + value: 'G-XXXXXXX', + secret: false // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.sites import Sites +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +sites = Sites(client) + +result: Variable = sites.create_variable( + site_id = '', + key = 'NEXT_PUBLIC_ANALYTICS_ID', + value = 'G-XXXXXXX', + secret = False # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +sites = Sites.new(client) + +result = sites.create_variable( + site_id: '', + key: 'NEXT_PUBLIC_ANALYTICS_ID', + value: 'G-XXXXXXX', + secret: false # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Sites sites = new Sites(client); + +Variable result = await sites.CreateVariable( + siteId: "", + key: "NEXT_PUBLIC_ANALYTICS_ID", + value: "G-XXXXXXX", + secret: false // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Sites sites = Sites(client); + +Variable result = await sites.createVariable( + siteId: '', + key: 'NEXT_PUBLIC_ANALYTICS_ID', + value: 'G-XXXXXXX', + secret: false, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Sites + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val sites = Sites(client) + +val response = sites.createVariable( + siteId = "", + key = "NEXT_PUBLIC_ANALYTICS_ID", + value = "G-XXXXXXX", + secret = false // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Sites; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Sites sites = new Sites(client); + +sites.createVariable( + "", // siteId + "NEXT_PUBLIC_ANALYTICS_ID", // key + "G-XXXXXXX", // value + false, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let sites = Sites(client) + +let variable = try await sites.createVariable( + siteId: "", + key: "NEXT_PUBLIC_ANALYTICS_ID", + value: "G-XXXXXXX", + secret: false // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +sites := appwrite.NewSites(client) + +response, error := sites.CreateVariable( + "", + "NEXT_PUBLIC_ANALYTICS_ID", + "G-XXXXXXX", + appwrite.WithCreateVariableSecret(false), +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Sites; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let sites = Sites::new(&client); + + let result = sites.create_variable( + "", + "NEXT_PUBLIC_ANALYTICS_ID", + "G-XXXXXXX", + Some(false) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Update a project variable + +`updateVariable` exists on all three services with the same shape. Updating a variable lets you rotate a value or change its secret flag without recreating it. Marking a variable as secret cannot be reversed. To replace a secret value, delete the variable and create a new one with the same key. + +{% multicode %} +```server-nodejs +import { Client, Project } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.updateVariable({ + variableId: '', + key: 'STRIPE_KEY', // optional + value: 'sk_live_rotated_...', // optional + secret: false // optional +}); +``` +```server-deno +import { Client, Project } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.updateVariable({ + variableId: '', + key: 'STRIPE_KEY', // optional + value: 'sk_live_rotated_...', // optional + secret: false // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$project = new Project($client); + +$result = $project->updateVariable( + variableId: '', + key: 'STRIPE_KEY', // optional + value: 'sk_live_rotated_...', // optional + secret: false // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.project import Project +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +project = Project(client) + +result: Variable = project.update_variable( + variable_id = '', + key = 'STRIPE_KEY', # optional + value = 'sk_live_rotated_...', # optional + secret = False # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +project = Project.new(client) + +result = project.update_variable( + variable_id: '', + key: 'STRIPE_KEY', # optional + value: 'sk_live_rotated_...', # optional + secret: false # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Project project = new Project(client); + +Variable result = await project.UpdateVariable( + variableId: "", + key: "STRIPE_KEY", // optional + value: "sk_live_rotated_...", // optional + secret: false // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Project project = Project(client); + +Variable result = await project.updateVariable( + variableId: '', + key: 'STRIPE_KEY', // (optional) + value: 'sk_live_rotated_...', // (optional) + secret: false, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Project + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val project = Project(client) + +val response = project.updateVariable( + variableId = "", + key = "STRIPE_KEY", // optional + value = "sk_live_rotated_...", // optional + secret = false // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Project; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Project project = new Project(client); + +project.updateVariable( + "", // variableId + "STRIPE_KEY", // key (optional) + "sk_live_rotated_...", // value (optional) + false, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let project = Project(client) + +let variable = try await project.updateVariable( + variableId: "", + key: "STRIPE_KEY", // optional + value: "sk_live_rotated_...", // optional + secret: false // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +project := appwrite.NewProject(client) + +response, error := project.UpdateVariable( + "", + appwrite.WithUpdateVariableKey("STRIPE_KEY"), + appwrite.WithUpdateVariableValue("sk_live_rotated_..."), + appwrite.WithUpdateVariableSecret(false), +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Project; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let project = Project::new(&client); + + let result = project.update_variable( + "", + Some("STRIPE_KEY"), // optional + Some("sk_live_rotated_..."), // optional + Some(false) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Delete a project variable + +`deleteVariable` is available on each service. Once deleted, the variable stops appearing in subsequent function and site deployments. + +{% multicode %} +```server-nodejs +import { Client, Project } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.deleteVariable({ + variableId: '' +}); +``` +```server-deno +import { Client, Project } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.deleteVariable({ + variableId: '' +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$project = new Project($client); + +$result = $project->deleteVariable( + variableId: '' +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.project import Project + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +project = Project(client) + +result = project.delete_variable( + variable_id = '' +) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +project = Project.new(client) + +result = project.delete_variable( + variable_id: '' +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Project project = new Project(client); + +await project.DeleteVariable( + variableId: "" +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Project project = Project(client); + +await project.deleteVariable( + variableId: '', +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Project + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val project = Project(client) + +val response = project.deleteVariable( + variableId = "" +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Project; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Project project = new Project(client); + +project.deleteVariable( + "", // variableId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let project = Project(client) + +let result = try await project.deleteVariable( + variableId: "" +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +project := appwrite.NewProject(client) + +response, error := project.DeleteVariable( + "", +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Project; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let project = Project::new(&client); + + project.delete_variable( + "" + ).await?; + + Ok(()) +} +``` +{% /multicode %} + +# Get started + +The Variables API is available on **Appwrite Cloud** today, across every Appwrite Server SDK. Complete code examples for every supported language and every operation live in the documentation: + +- [Project variables](/docs/advanced/platform/environment-variables) +- [Function variables](/docs/products/functions/environment-variables) +- [Site variables](/docs/products/sites/environment-variables) diff --git a/src/routes/changelog/(entries)/2026-04-28.markdoc b/src/routes/changelog/(entries)/2026-04-28.markdoc new file mode 100644 index 0000000000..f0715386e4 --- /dev/null +++ b/src/routes/changelog/(entries)/2026-04-28.markdoc @@ -0,0 +1,14 @@ +--- +layout: changelog +title: "Variables API: manage function, site, and project variables with Server SDKs" +date: 2026-04-28 +cover: /images/blog/announcing-variables-api/cover.png +--- + +Environment variables for functions, sites, and projects can now be created, listed, retrieved, updated, and deleted programmatically through the Appwrite Server SDKs. Two new API key scopes, `project.read` and `project.write`, control access to the project-scoped endpoints, alongside the existing `functions.*` and `sites.*` scopes for resource-scoped variables. + +This enables configuration as code, one-place rotation of secrets shared across multiple resources, and repeatable bootstraps of new environments and tenants from scripts or templates. + +{% arrow_link href="/blog/post/announcing-variables-api" %} +Read the announcement +{% /arrow_link %} diff --git a/src/routes/docs/advanced/platform/+layout.svelte b/src/routes/docs/advanced/platform/+layout.svelte index 5e1739b622..219c63c770 100644 --- a/src/routes/docs/advanced/platform/+layout.svelte +++ b/src/routes/docs/advanced/platform/+layout.svelte @@ -126,6 +126,11 @@ label: 'Custom domains', href: '/docs/advanced/platform/custom-domains' }, + { + label: 'Environment variables', + new: isNewUntil('30 May 2026'), + href: '/docs/advanced/platform/environment-variables' + }, { label: 'Message templates', href: '/docs/advanced/platform/message-templates' diff --git a/src/routes/docs/advanced/platform/environment-variables/+page.markdoc b/src/routes/docs/advanced/platform/environment-variables/+page.markdoc new file mode 100644 index 0000000000..dcfbee2042 --- /dev/null +++ b/src/routes/docs/advanced/platform/environment-variables/+page.markdoc @@ -0,0 +1,1219 @@ +--- +layout: article +title: Environment variables +description: Use project, function, and site environment variables to pass constants and secrets to your Appwrite Functions and Appwrite Sites at build and runtime. +--- + +Environment variables let you pass constants and secrets such as API keys, connection strings, and feature flags into your Appwrite Functions and Appwrite Sites at build and runtime. Storing values outside your source keeps secrets out of version control and lets you change configuration without code changes. + +Appwrite supports three scopes of environment variables: + +- **Project variables** are shared across every function and site in the project. Use them for values consumed by more than one resource, such as a shared third-party API key, a database URL, or a feature flag. +- **Function variables** are scoped to a single function. Use them for values only that function needs. +- **Site variables** are scoped to a single site. Use them for values only that site needs. + +When the same key is defined in multiple scopes, the more specific scope wins. Function or site variables override project variables, and Appwrite-injected variables (those prefixed with `APPWRITE_`) take final precedence and cannot be overridden. + +{% info title="Redeployment required" %} +Variable changes only take effect on the next deployment. Redeploy your functions or sites after creating, updating, or deleting variables. +{% /info %} + +# Project variables {% #project-variables %} + +Project variables are available to every function and site in your project. They are managed at the project level and merged into each function or site's environment automatically at build and runtime. + +This page covers how to manage project variables. To manage variables on a single function or site, see the dedicated pages: + +{% cards %} +{% cards_item href="/docs/products/functions/environment-variables" title="Function variables" %} +Manage variables for a single function. +{% /cards_item %} +{% cards_item href="/docs/products/sites/environment-variables" title="Site variables" %} +Manage variables for a single site. +{% /cards_item %} +{% /cards %} + +# Manage in the Console {% #console %} + +You can create and manage project variables from the Appwrite Console. The Console refers to them as **Global variables**: + +1. Navigate to your project. +2. Open **Settings** and scroll to the **Global variables** section. +3. Click **Create a global variable** and enter a key and value. +4. Optionally select the **Secret** checkbox to prevent any team member from reading the value after creation. +5. Click **Create**, then redeploy your functions and sites for the change to take effect. + +{% only_dark %} +![Project Global variables in the Appwrite Console](/images/docs/platform/dark/env-variables.png) +{% /only_dark %} +{% only_light %} +![Project Global variables in the Appwrite Console](/images/docs/platform/env-variables.png) +{% /only_light %} + +# Manage with a Server SDK {% #server-sdks %} + +You can also manage project variables programmatically using a [Server SDK](/docs/sdks#server). Each call requires an [API key](/docs/advanced/platform/api-keys) with the `project.write` scope to create, update, or delete variables, or the `project.read` scope to list and read them. + +## Create a variable {% #create-variable %} + +{% multicode %} +```server-nodejs +import { Client, Project, ID } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.createVariable({ + variableId: ID.unique(), + key: '', + value: '', + secret: false // optional +}); +``` +```server-deno +import { Client, Project, ID } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.createVariable({ + variableId: ID.unique(), + key: '', + value: '', + secret: false // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$project = new Project($client); + +$result = $project->createVariable( + variableId: ID::unique(), + key: '', + value: '', + secret: false // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.id import ID +from appwrite.services.project import Project +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +project = Project(client) + +result: Variable = project.create_variable( + variable_id = ID.unique(), + key = '', + value = '', + secret = False # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +project = Project.new(client) + +result = project.create_variable( + variable_id: ID.unique(), + key: '', + value: '', + secret: false # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Project project = new Project(client); + +Variable result = await project.CreateVariable( + variableId: ID.Unique(), + key: "", + value: "", + secret: false // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Project project = Project(client); + +Variable result = await project.createVariable( + variableId: ID.unique(), + key: '', + value: '', + secret: false, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.ID +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Project + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val project = Project(client) + +val response = project.createVariable( + variableId = ID.unique(), + key = "", + value = "", + secret = false // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.ID; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Project; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Project project = new Project(client); + +project.createVariable( + ID.unique(), // variableId + "", // key + "", // value + false, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let project = Project(client) + +let variable = try await project.createVariable( + variableId: ID.unique(), + key: "", + value: "", + secret: false // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" + "github.com/appwrite/sdk-for-go/id" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +project := appwrite.NewProject(client) + +response, error := project.CreateVariable( + id.Unique(), + "", + "", + appwrite.WithCreateVariableSecret(false), +) +``` +```server-rust +use appwrite::Client; +use appwrite::id::ID; +use appwrite::services::Project; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let project = Project::new(&client); + + let result = project.create_variable( + &ID::unique(), + "", + "", + Some(false) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## List variables {% #list-variables %} + +You can paginate, filter, and sort the result. See [Queries](/docs/products/databases/queries) for the query syntax. The list endpoint accepts queries on the `key`, `value`, and `secret` attributes. + +{% multicode %} +```server-nodejs +import { Client, Project } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.listVariables({ + queries: [], // optional + total: false // optional +}); +``` +```server-deno +import { Client, Project } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.listVariables({ + queries: [], // optional + total: false // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$project = new Project($client); + +$result = $project->listVariables( + queries: [], // optional + total: false // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.project import Project +from appwrite.models import VariableList + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +project = Project(client) + +result: VariableList = project.list_variables( + queries = [], # optional + total = False # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +project = Project.new(client) + +result = project.list_variables( + queries: [], # optional + total: false # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Project project = new Project(client); + +VariableList result = await project.ListVariables( + queries: new List(), // optional + total: false // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Project project = Project(client); + +VariableList result = await project.listVariables( + queries: [], // (optional) + total: false, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Project + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val project = Project(client) + +val response = project.listVariables( + queries = listOf(), // optional + total = false // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Project; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Project project = new Project(client); + +project.listVariables( + List.of(), // queries (optional) + false, // total (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let project = Project(client) + +let variableList = try await project.listVariables( + queries: [], // optional + total: false // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +project := appwrite.NewProject(client) + +response, error := project.ListVariables( + appwrite.WithListVariablesQueries([]interface{}{}), + appwrite.WithListVariablesTotal(false), +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Project; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let project = Project::new(&client); + + let result = project.list_variables( + Some(vec![]), // optional + Some(false) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Get a variable {% #get-variable %} + +{% multicode %} +```server-nodejs +import { Client, Project } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.getVariable({ + variableId: '' +}); +``` +```server-deno +import { Client, Project } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.getVariable({ + variableId: '' +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$project = new Project($client); + +$result = $project->getVariable( + variableId: '' +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.project import Project +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +project = Project(client) + +result: Variable = project.get_variable( + variable_id = '' +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +project = Project.new(client) + +result = project.get_variable( + variable_id: '' +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Project project = new Project(client); + +Variable result = await project.GetVariable( + variableId: "" +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Project project = Project(client); + +Variable result = await project.getVariable( + variableId: '', +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Project + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val project = Project(client) + +val response = project.getVariable( + variableId = "" +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Project; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Project project = new Project(client); + +project.getVariable( + "", // variableId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let project = Project(client) + +let variable = try await project.getVariable( + variableId: "" +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +project := appwrite.NewProject(client) + +response, error := project.GetVariable( + "", +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Project; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let project = Project::new(&client); + + let result = project.get_variable( + "" + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Update a variable {% #update-variable %} + +You can change a variable's `key`, `value`, or `secret` flag. Marking a variable as secret is one-way. Once set, the value is no longer readable from the Console or API. + +{% multicode %} +```server-nodejs +import { Client, Project } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.updateVariable({ + variableId: '', + key: '', // optional + value: '', // optional + secret: false // optional +}); +``` +```server-deno +import { Client, Project } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.updateVariable({ + variableId: '', + key: '', // optional + value: '', // optional + secret: false // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$project = new Project($client); + +$result = $project->updateVariable( + variableId: '', + key: '', // optional + value: '', // optional + secret: false // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.project import Project +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +project = Project(client) + +result: Variable = project.update_variable( + variable_id = '', + key = '', # optional + value = '', # optional + secret = False # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +project = Project.new(client) + +result = project.update_variable( + variable_id: '', + key: '', # optional + value: '', # optional + secret: false # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Project project = new Project(client); + +Variable result = await project.UpdateVariable( + variableId: "", + key: "", // optional + value: "", // optional + secret: false // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Project project = Project(client); + +Variable result = await project.updateVariable( + variableId: '', + key: '', // (optional) + value: '', // (optional) + secret: false, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Project + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val project = Project(client) + +val response = project.updateVariable( + variableId = "", + key = "", // optional + value = "", // optional + secret = false // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Project; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Project project = new Project(client); + +project.updateVariable( + "", // variableId + "", // key (optional) + "", // value (optional) + false, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let project = Project(client) + +let variable = try await project.updateVariable( + variableId: "", + key: "", // optional + value: "", // optional + secret: false // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +project := appwrite.NewProject(client) + +response, error := project.UpdateVariable( + "", + appwrite.WithUpdateVariableKey(""), + appwrite.WithUpdateVariableValue(""), + appwrite.WithUpdateVariableSecret(false), +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Project; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let project = Project::new(&client); + + let result = project.update_variable( + "", + Some(""), // optional + Some(""), // optional + Some(false) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Delete a variable {% #delete-variable %} + +{% multicode %} +```server-nodejs +import { Client, Project } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.deleteVariable({ + variableId: '' +}); +``` +```server-deno +import { Client, Project } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const project = new Project(client); + +const result = await project.deleteVariable({ + variableId: '' +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$project = new Project($client); + +$result = $project->deleteVariable( + variableId: '' +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.project import Project + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +project = Project(client) + +result = project.delete_variable( + variable_id = '' +) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +project = Project.new(client) + +result = project.delete_variable( + variable_id: '' +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Project project = new Project(client); + +await project.DeleteVariable( + variableId: "" +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Project project = Project(client); + +await project.deleteVariable( + variableId: '', +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Project + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val project = Project(client) + +val response = project.deleteVariable( + variableId = "" +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Project; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Project project = new Project(client); + +project.deleteVariable( + "", // variableId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let project = Project(client) + +let result = try await project.deleteVariable( + variableId: "" +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +project := appwrite.NewProject(client) + +response, error := project.DeleteVariable( + "", +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Project; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let project = Project::new(&client); + + project.delete_variable( + "" + ).await?; + + Ok(()) +} +``` +{% /multicode %} + +# Secret variables {% #secret-variables %} + +Mark a variable as **Secret** to hide its value from the Console and API after creation. Only the function or site runtime can read the value at build and runtime. Team members and external integrations cannot retrieve it after creation. + +You can mark a variable as secret either when you create it or by updating an existing variable. Marking a variable as secret cannot be reversed. To replace a secret value, delete the variable and create a new one with the same key. + +# Override behavior {% #overrides %} + +When the same key is defined in multiple scopes, more specific scopes take precedence: + +1. Project variables are merged into the runtime environment first. +2. Function or site variables override matching keys from project scope. +3. Appwrite-injected variables (those prefixed with `APPWRITE_`) override matching keys from both scopes and cannot be customized. + +This lets you set a default at the project level (for example, `LOG_LEVEL=info`) and override it for a specific function or site that needs different behavior. + +# Limits {% #limits %} + +| Field | Limit | +|----------------|------------------------------------------------| +| Variable ID | 36 characters, `a-z A-Z 0-9 . - _` | +| Key | 255 characters | +| Value | 8192 characters | +| Reserved keys | Any key starting with `APPWRITE_` is reserved | diff --git a/src/routes/docs/products/functions/+layout.svelte b/src/routes/docs/products/functions/+layout.svelte index 0dcc198176..a6ae8dfcee 100644 --- a/src/routes/docs/products/functions/+layout.svelte +++ b/src/routes/docs/products/functions/+layout.svelte @@ -40,6 +40,10 @@ label: 'Domains', href: '/docs/products/functions/domains' }, + { + label: 'Environment variables', + href: '/docs/products/functions/environment-variables' + }, { label: 'Runtimes', href: '/docs/products/functions/runtimes' diff --git a/src/routes/docs/products/functions/develop/+page.markdoc b/src/routes/docs/products/functions/develop/+page.markdoc index 348f99b288..455497ee57 100644 --- a/src/routes/docs/products/functions/develop/+page.markdoc +++ b/src/routes/docs/products/functions/develop/+page.markdoc @@ -1318,133 +1318,13 @@ You can access these logs through the following steps. 3. Under the Executions tab, click on an execution. 4. In the Response section, you'll be able to view logs under the Logs and Errors tabs. -# Accessing environment variables {% #environment-variables %} -If you need to pass constants or secrets to Appwrite Functions, you can use environment variables. - -| Variable | Description | Available at Build and/or Run Time | -|-----------------------------------|------------------------------------------------|-----------------------------------------------------| -| `APPWRITE_FUNCTION_API_ENDPOINT` | The API endpoint of the running function | Both | -| `APPWRITE_VERSION` | The Appwrite version used to run the function | Both | -| `APPWRITE_REGION` | The region where the function will run from | Both | -| `APPWRITE_FUNCTION_API_KEY` | The function API key is used for server authentication | Build time | -| `APPWRITE_FUNCTION_ID` | The ID of the running function. | Both | -| `APPWRITE_FUNCTION_NAME` | The Name of the running function. | Both | -| `APPWRITE_FUNCTION_DEPLOYMENT` | The deployment ID of the running function. | Both | -| `APPWRITE_FUNCTION_PROJECT_ID` | The project ID of the running function. | Both | -| `APPWRITE_FUNCTION_RUNTIME_NAME` | The runtime of the running function. | Both | -| `APPWRITE_FUNCTION_RUNTIME_VERSION` | The runtime version of the running function. | Both | - -{% arrow_link href="/docs/products/functions/functions#environment-variables" %} -Learn to add variables to you function -{% /arrow_link %} - -You can access the environment variables through the systems library of each language. - -{% multicode %} -```server-nodejs -export default async ({ req, res, log }) => { - return res.text(process.env.MY_VAR); -} -``` -```php -res->text(getenv('MY_VAR')); -}; -``` -```python -def main(context): - return context.res.text(os.environ['MY_VAR']) -``` -```ruby -def main(context) - return context.res.text(ENV['MY_VAR']) -end -``` -```deno -export default async ({ req, res, log }) => { - return res.text(Deno.env.get('MY_VAR')); -} -``` -```go -package handler - -import ( - "os" +# Environment variables {% #environment-variables %} - "github.com/open-runtimes/types-for-go/v4/openruntimes" -) +Pass constants and secrets into your function with environment variables, and read them inside your function using your runtime's standard environment lookup. -func Main(Context openruntimes.Context) openruntimes.Response { - return res.text(os.Getenv(MY_VAR)) -} -``` -```dart -import 'dart:io'; -import 'dart:async'; - -Future main(final context) async { - return context.res.text(Platform.environment['MY_VAR']); -} -``` -```swift -import Foundation - -func main(context: RuntimeContext) async throws -> RuntimeOutput { - return context.res.text(ProcessInfo.processInfo.environment["MY_VAR"]) -} -``` -```csharp -namespace DotNetRuntime; - -public class Handler { - public async Task Main(RuntimeContext Context) - { - return Context.Res.Text(Environment.GetEnvironmentVariable("MY_VAR")); - } -} -``` -```kotlin -package io.openruntimes.kotlin.src - -import io.openruntimes.kotlin.RuntimeContext -import io.openruntimes.kotlin.RuntimeOutput - -class Main { - fun main(context: RuntimeContext): RuntimeOutput { - return context.res.text(System.getenv("MY_VAR")) - } -} -``` -```java -package io.openruntimes.java.src; - -import io.openruntimes.java.RuntimeContext; -import io.openruntimes.java.RuntimeOutput; - -public class Main { - public RuntimeOutput main(RuntimeContext context) throws Exception { - return context.getRes().text(System.getenv("MY_VAR")); - } -} -``` -```cpp -#include "../RuntimeResponse.h" -#include "../RuntimeRequest.h" -#include "../RuntimeOutput.h" -#include "../RuntimeContext.h" - -namespace runtime { - class Handler { - public: - static RuntimeOutput main(RuntimeContext &context) { - return context.res.text(std::getenv("MY_VAR")); - } - }; -} -``` -{% /multicode %} +{% arrow_link href="/docs/products/functions/environment-variables" %} +Manage and read environment variables +{% /arrow_link %} # Dependencies {% #dependencies %} To install your dependencies before your function is built, diff --git a/src/routes/docs/products/functions/environment-variables/+page.markdoc b/src/routes/docs/products/functions/environment-variables/+page.markdoc new file mode 100644 index 0000000000..3e97d41546 --- /dev/null +++ b/src/routes/docs/products/functions/environment-variables/+page.markdoc @@ -0,0 +1,1307 @@ +--- +layout: article +title: Environment variables +description: Set environment variables for your Appwrite Functions to pass constants and secrets at build and runtime. +--- + +Appwrite Functions can read environment variables at build and runtime. Use them to pass constants and secrets such as API keys, connection strings, and feature flags without hardcoding them in your source. + +A function reads from three sources, in this order of precedence: + +1. **Project variables** are shared across every function and site in your project. Set them once and every function inherits them automatically. See [project variables](/docs/advanced/platform/environment-variables) for the platform-wide reference. +2. **Function variables** are scoped to a single function. Override a project variable for one function by setting the same key on the function itself. +3. **Appwrite-injected variables** are set by Appwrite at execution time (for example, `APPWRITE_FUNCTION_PROJECT_ID`). These take final precedence and cannot be overridden. + +{% info title="Redeployment required" %} +Variable changes only take effect on the next deployment. Redeploy your function after creating, updating, or deleting variables. +{% /info %} + +# Manage in the Console {% #console %} + +1. Navigate to your function in the Appwrite Console. +2. Open the **Settings** tab > **Environment variables** section. +3. Click **Create variable** and enter a key and value. +4. Optionally select the **Secret** checkbox to prevent any team member from reading the value after creation. +5. Click **Create**, then redeploy the function for the change to take effect. + +{% only_dark %} +![Function environment variables](/images/docs/functions/dark/env-variables.png) +{% /only_dark %} +{% only_light %} +![Function environment variables](/images/docs/functions/env-variables.png) +{% /only_light %} + +You can also configure global variables that apply to all your functions from your project's **Settings** page. See [project variables](/docs/advanced/platform/environment-variables) for details. + +# Manage with a Server SDK {% #server-sdks %} + +You can also manage function variables programmatically using a [Server SDK](/docs/sdks#server). Each call requires an [API key](/docs/advanced/platform/api-keys) with the `functions.write` scope to create, update, or delete variables, or the `functions.read` scope to list and read them. + +## Create a variable {% #create-variable %} + +{% multicode %} +```server-nodejs +import { Client, Functions } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.createVariable({ + functionId: '', + key: '', + value: '', + secret: false // optional +}); +``` +```server-deno +import { Client, Functions } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.createVariable({ + functionId: '', + key: '', + value: '', + secret: false // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$functions = new Functions($client); + +$result = $functions->createVariable( + functionId: '', + key: '', + value: '', + secret: false // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.functions import Functions +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +functions = Functions(client) + +result: Variable = functions.create_variable( + function_id = '', + key = '', + value = '', + secret = False # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +functions = Functions.new(client) + +result = functions.create_variable( + function_id: '', + key: '', + value: '', + secret: false # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Functions functions = new Functions(client); + +Variable result = await functions.CreateVariable( + functionId: "", + key: "", + value: "", + secret: false // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Functions functions = Functions(client); + +Variable result = await functions.createVariable( + functionId: '', + key: '', + value: '', + secret: false, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Functions + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val functions = Functions(client) + +val response = functions.createVariable( + functionId = "", + key = "", + value = "", + secret = false // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Functions; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Functions functions = new Functions(client); + +functions.createVariable( + "", // functionId + "", // key + "", // value + false, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let functions = Functions(client) + +let variable = try await functions.createVariable( + functionId: "", + key: "", + value: "", + secret: false // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +functions := appwrite.NewFunctions(client) + +response, error := functions.CreateVariable( + "", + "", + "", + appwrite.WithCreateVariableSecret(false), +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Functions; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let functions = Functions::new(&client); + + let result = functions.create_variable( + "", + "", + "", + Some(false) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## List variables {% #list-variables %} + +{% multicode %} +```server-nodejs +import { Client, Functions } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.listVariables({ + functionId: '' +}); +``` +```server-deno +import { Client, Functions } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.listVariables({ + functionId: '' +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$functions = new Functions($client); + +$result = $functions->listVariables( + functionId: '' +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.functions import Functions +from appwrite.models import VariableList + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +functions = Functions(client) + +result: VariableList = functions.list_variables( + function_id = '' +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +functions = Functions.new(client) + +result = functions.list_variables( + function_id: '' +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Functions functions = new Functions(client); + +VariableList result = await functions.ListVariables( + functionId: "" +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Functions functions = Functions(client); + +VariableList result = await functions.listVariables( + functionId: '', +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Functions + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val functions = Functions(client) + +val response = functions.listVariables( + functionId = "" +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Functions; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Functions functions = new Functions(client); + +functions.listVariables( + "", // functionId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let functions = Functions(client) + +let variableList = try await functions.listVariables( + functionId: "" +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +functions := appwrite.NewFunctions(client) + +response, error := functions.ListVariables( + "", +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Functions; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let functions = Functions::new(&client); + + let result = functions.list_variables( + "" + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Get a variable {% #get-variable %} + +{% multicode %} +```server-nodejs +import { Client, Functions } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.getVariable({ + functionId: '', + variableId: '' +}); +``` +```server-deno +import { Client, Functions } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.getVariable({ + functionId: '', + variableId: '' +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$functions = new Functions($client); + +$result = $functions->getVariable( + functionId: '', + variableId: '' +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.functions import Functions +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +functions = Functions(client) + +result: Variable = functions.get_variable( + function_id = '', + variable_id = '' +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +functions = Functions.new(client) + +result = functions.get_variable( + function_id: '', + variable_id: '' +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Functions functions = new Functions(client); + +Variable result = await functions.GetVariable( + functionId: "", + variableId: "" +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Functions functions = Functions(client); + +Variable result = await functions.getVariable( + functionId: '', + variableId: '', +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Functions + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val functions = Functions(client) + +val response = functions.getVariable( + functionId = "", + variableId = "" +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Functions; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Functions functions = new Functions(client); + +functions.getVariable( + "", // functionId + "", // variableId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let functions = Functions(client) + +let variable = try await functions.getVariable( + functionId: "", + variableId: "" +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +functions := appwrite.NewFunctions(client) + +response, error := functions.GetVariable( + "", + "", +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Functions; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let functions = Functions::new(&client); + + let result = functions.get_variable( + "", + "" + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Update a variable {% #update-variable %} + +You can change a variable's `key`, `value`, or `secret` flag. Marking a variable as secret is one-way. Once set, the value is no longer readable from the Console or API. + +{% multicode %} +```server-nodejs +import { Client, Functions } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.updateVariable({ + functionId: '', + variableId: '', + key: '', + value: '', // optional + secret: false // optional +}); +``` +```server-deno +import { Client, Functions } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.updateVariable({ + functionId: '', + variableId: '', + key: '', + value: '', // optional + secret: false // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$functions = new Functions($client); + +$result = $functions->updateVariable( + functionId: '', + variableId: '', + key: '', + value: '', // optional + secret: false // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.functions import Functions +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +functions = Functions(client) + +result: Variable = functions.update_variable( + function_id = '', + variable_id = '', + key = '', + value = '', # optional + secret = False # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +functions = Functions.new(client) + +result = functions.update_variable( + function_id: '', + variable_id: '', + key: '', + value: '', # optional + secret: false # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Functions functions = new Functions(client); + +Variable result = await functions.UpdateVariable( + functionId: "", + variableId: "", + key: "", + value: "", // optional + secret: false // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Functions functions = Functions(client); + +Variable result = await functions.updateVariable( + functionId: '', + variableId: '', + key: '', + value: '', // (optional) + secret: false, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Functions + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val functions = Functions(client) + +val response = functions.updateVariable( + functionId = "", + variableId = "", + key = "", + value = "", // optional + secret = false // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Functions; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Functions functions = new Functions(client); + +functions.updateVariable( + "", // functionId + "", // variableId + "", // key + "", // value (optional) + false, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let functions = Functions(client) + +let variable = try await functions.updateVariable( + functionId: "", + variableId: "", + key: "", + value: "", // optional + secret: false // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +functions := appwrite.NewFunctions(client) + +response, error := functions.UpdateVariable( + "", + "", + "", + appwrite.WithUpdateVariableValue(""), + appwrite.WithUpdateVariableSecret(false), +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Functions; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let functions = Functions::new(&client); + + let result = functions.update_variable( + "", + "", + "", + Some(""), // optional + Some(false) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Delete a variable {% #delete-variable %} + +{% multicode %} +```server-nodejs +import { Client, Functions } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.deleteVariable({ + functionId: '', + variableId: '' +}); +``` +```server-deno +import { Client, Functions } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const functions = new Functions(client); + +const result = await functions.deleteVariable({ + functionId: '', + variableId: '' +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$functions = new Functions($client); + +$result = $functions->deleteVariable( + functionId: '', + variableId: '' +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.functions import Functions + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +functions = Functions(client) + +result = functions.delete_variable( + function_id = '', + variable_id = '' +) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +functions = Functions.new(client) + +result = functions.delete_variable( + function_id: '', + variable_id: '' +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Functions functions = new Functions(client); + +await functions.DeleteVariable( + functionId: "", + variableId: "" +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Functions functions = Functions(client); + +await functions.deleteVariable( + functionId: '', + variableId: '', +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Functions + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val functions = Functions(client) + +val response = functions.deleteVariable( + functionId = "", + variableId = "" +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Functions; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Functions functions = new Functions(client); + +functions.deleteVariable( + "", // functionId + "", // variableId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let functions = Functions(client) + +let result = try await functions.deleteVariable( + functionId: "", + variableId: "" +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +functions := appwrite.NewFunctions(client) + +response, error := functions.DeleteVariable( + "", + "", +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Functions; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let functions = Functions::new(&client); + + functions.delete_variable( + "", + "" + ).await?; + + Ok(()) +} +``` +{% /multicode %} + +# Read variables in your function {% #read-variables %} + +Once a variable is set, you can read it inside your function using your runtime language's standard environment lookup. + +{% multicode %} +```server-nodejs +export default async ({ req, res, log }) => { + return res.text(process.env.MY_VAR); +} +``` +```server-deno +export default async ({ req, res, log }) => { + return res.text(Deno.env.get('MY_VAR')); +} +``` +```server-php +res->text(getenv('MY_VAR')); +}; +``` +```server-python +def main(context): + return context.res.text(os.environ['MY_VAR']) +``` +```server-ruby +def main(context) + return context.res.text(ENV['MY_VAR']) +end +``` +```server-dotnet +namespace DotNetRuntime; + +public class Handler { + public async Task Main(RuntimeContext Context) { + var myVar = Environment.GetEnvironmentVariable("MY_VAR"); + return Context.Res.Text(myVar); + } +} +``` +```server-dart +import 'dart:io'; +import 'dart:async'; + +Future main(final context) async { + return context.res.text(Platform.environment['MY_VAR']); +} +``` +```server-kotlin +import io.openruntimes.kotlin.RuntimeContext +import io.openruntimes.kotlin.RuntimeOutput + +class Handler { + suspend fun main(context: RuntimeContext): RuntimeOutput { + return context.res.text(System.getenv("MY_VAR")) + } +} +``` +```server-java +import io.openruntimes.java.RuntimeContext; +import io.openruntimes.java.RuntimeOutput; + +public class Handler { + public RuntimeOutput main(RuntimeContext context) throws Exception { + return context.res.text(System.getenv("MY_VAR")); + } +} +``` +```server-swift +import Foundation + +func main(context: RuntimeContext) async throws -> RuntimeOutput { + return context.res.text(ProcessInfo.processInfo.environment["MY_VAR"] ?? "") +} +``` +```server-go +package handler + +import ( + "os" + + "github.com/open-runtimes/types-for-go/v4/openruntimes" +) + +func Main(Context openruntimes.Context) openruntimes.Response { + return Context.Res.Text(os.Getenv("MY_VAR")) +} +``` +{% /multicode %} + +# Appwrite-injected variables {% #appwrite-variables %} + +Appwrite passes the following environment variables into every function deployment by default. They take precedence over your own variables, so do not set keys with the `APPWRITE_` prefix. + +{% partial file="functions-env-vars.md" /%} + +During the build process, dynamic API keys are automatically provided as the environment variable `APPWRITE_FUNCTION_API_KEY`. This environment variable does not need to be initialized. + +# Secret variables {% #secret-variables %} + +Mark a variable as **Secret** to hide its value from the Console and API after creation. Only the function runtime can read the value at build and runtime. Team members and external integrations cannot retrieve it after creation. + +You can mark a variable as secret either when you create it or by updating an existing variable. Marking a variable as secret cannot be reversed. To replace a secret value, delete the variable and create a new one with the same key. + +# Limits {% #limits %} + +| Field | Limit | +|----------------|------------------------------------------------| +| Variable ID | 36 characters, `a-z A-Z 0-9 . - _` | +| Key | 255 characters | +| Value | 8192 characters | +| Reserved keys | Any key starting with `APPWRITE_` is reserved | diff --git a/src/routes/docs/products/functions/functions/+page.markdoc b/src/routes/docs/products/functions/functions/+page.markdoc index 0fd108ab7e..13995ab960 100644 --- a/src/routes/docs/products/functions/functions/+page.markdoc +++ b/src/routes/docs/products/functions/functions/+page.markdoc @@ -160,18 +160,6 @@ Here are some cron expressions for common intervals: | `0 0 * * *` | Every day at 00:00 | | `0 0 * * 1` | Every Monday at 00:00 | -## Environment variables {% #environment-variables %} -Set static environment variables that will be passed to your function -by navigating to your function > **Settings** > **Environment variables**. - -You can also configure global variables that apply to all your functions in the **Settings** of your project. - -{% info title="Redeployment required" %} -This change requires your function to be redeployed to take effect. -{% /info %} - -You can access environment variables inside functions using your [runtime language's system methods](/docs/products/functions/develop#environment-variables). - ## Timeout {% #timeout %} You can limit the execution time of your function by navigating to your function > **Settings** > **Timeout**. There is a system wide maximum timeout of 900 seconds (15 minutes). diff --git a/src/routes/docs/products/sites/+layout.svelte b/src/routes/docs/products/sites/+layout.svelte index 872e412b84..36454587f7 100644 --- a/src/routes/docs/products/sites/+layout.svelte +++ b/src/routes/docs/products/sites/+layout.svelte @@ -48,6 +48,10 @@ label: 'Domains', href: '/docs/products/sites/domains' }, + { + label: 'Environment variables', + href: '/docs/products/sites/environment-variables' + }, { label: 'Frameworks', href: '/docs/products/sites/frameworks' diff --git a/src/routes/docs/products/sites/develop/+page.markdoc b/src/routes/docs/products/sites/develop/+page.markdoc index ed8a2422b1..504172c701 100644 --- a/src/routes/docs/products/sites/develop/+page.markdoc +++ b/src/routes/docs/products/sites/develop/+page.markdoc @@ -28,41 +28,6 @@ You can configure your preferred rendering strategy through the following steps: ![Rendering strategy](/images/docs/sites/build-settings-rendering-ssr.png) {% /only_light %} -# **Accessing environment variables** - -Appwrite Sites lets you set static environment variables to pass constants and secrets such as API keys, connection strings, etc., to your sites. - -To set static environment variables, follow these steps: - -1. Navigate to your site on Appwrite Console. -2. Head to the **Settings** tab > **Environment variables** section. -3. Click on the **Create variable** button and add the key and value of the environment variable. -4. Select the **Secret** checkbox if you want to prevent any team member from reading the value of the environment variable after creation. -5. Click on the **Create** button and redeploy the site. - -{% only_dark %} -![Environment variables](/images/docs/sites/dark/env-variables.png) -{% /only_dark %} -{% only_light %} -![Environment variables](/images/docs/sites/env-variables.png) -{% /only_light %} - -You can also configure global variables that apply to all your sites in the **Settings** of your project. - -{% info title="Secret environment variables" %} - -Appwrite now allows you create secret environment variables, which are hidden from both the Appwrite Console and API. Once a variable is marked as secret, this action cannot be reversed. - -You can mark an environment variable as secret either at the time of creation or after it is created. - -{% /info %} - -## Appwrite-specific environment variables - -Appwrite passes the following environment variables into every deployed site by default. - -{% partial file="sites-env-vars.md" /%} - # Timeouts {% #timeouts %} Each request made to a path on an Appwrite Site has a set time limit, after which the request will timeout. Here are the steps to configure those timeout period: diff --git a/src/routes/docs/products/sites/environment-variables/+page.markdoc b/src/routes/docs/products/sites/environment-variables/+page.markdoc new file mode 100644 index 0000000000..fff8b25c42 --- /dev/null +++ b/src/routes/docs/products/sites/environment-variables/+page.markdoc @@ -0,0 +1,1220 @@ +--- +layout: article +title: Environment variables +description: Set environment variables for your Appwrite Sites to pass constants and secrets at build and runtime. +--- + +Appwrite Sites can read environment variables at build and runtime. Use them to pass constants and secrets such as API keys, connection strings, and feature flags without hardcoding them in your source. + +A site reads from three sources, in this order of precedence: + +1. **Project variables** are shared across every function and site in your project. Set them once and every site inherits them automatically. See [project variables](/docs/advanced/platform/environment-variables) for the platform-wide reference. +2. **Site variables** are scoped to a single site. Override a project variable for one site by setting the same key on the site itself. +3. **Appwrite-injected variables** are set by Appwrite at deployment time (for example, `APPWRITE_SITE_PROJECT_ID`). These take final precedence and cannot be overridden. + +{% info title="Redeployment required" %} +Variable changes only take effect on the next deployment. Redeploy your site after creating, updating, or deleting variables. +{% /info %} + +# Manage in the Console {% #console %} + +1. Navigate to your site in the Appwrite Console. +2. Open the **Settings** tab > **Environment variables** section. +3. Click **Create variable** and enter a key and value. +4. Optionally select the **Secret** checkbox to prevent any team member from reading the value after creation. +5. Click **Create**, then redeploy the site for the change to take effect. + +{% only_dark %} +![Site environment variables](/images/docs/sites/dark/env-variables.png) +{% /only_dark %} +{% only_light %} +![Site environment variables](/images/docs/sites/env-variables.png) +{% /only_light %} + +You can also configure global variables that apply to all your sites from your project's **Settings** page. See [project variables](/docs/advanced/platform/environment-variables) for details. + +# Manage with a Server SDK {% #server-sdks %} + +You can also manage site variables programmatically using a [Server SDK](/docs/sdks#server). Each call requires an [API key](/docs/advanced/platform/api-keys) with the `sites.write` scope to create, update, or delete variables, or the `sites.read` scope to list and read them. + +## Create a variable {% #create-variable %} + +{% multicode %} +```server-nodejs +import { Client, Sites } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.createVariable({ + siteId: '', + key: '', + value: '', + secret: false // optional +}); +``` +```server-deno +import { Client, Sites } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.createVariable({ + siteId: '', + key: '', + value: '', + secret: false // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$sites = new Sites($client); + +$result = $sites->createVariable( + siteId: '', + key: '', + value: '', + secret: false // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.sites import Sites +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +sites = Sites(client) + +result: Variable = sites.create_variable( + site_id = '', + key = '', + value = '', + secret = False # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +sites = Sites.new(client) + +result = sites.create_variable( + site_id: '', + key: '', + value: '', + secret: false # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Sites sites = new Sites(client); + +Variable result = await sites.CreateVariable( + siteId: "", + key: "", + value: "", + secret: false // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Sites sites = Sites(client); + +Variable result = await sites.createVariable( + siteId: '', + key: '', + value: '', + secret: false, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Sites + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val sites = Sites(client) + +val response = sites.createVariable( + siteId = "", + key = "", + value = "", + secret = false // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Sites; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Sites sites = new Sites(client); + +sites.createVariable( + "", // siteId + "", // key + "", // value + false, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let sites = Sites(client) + +let variable = try await sites.createVariable( + siteId: "", + key: "", + value: "", + secret: false // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +sites := appwrite.NewSites(client) + +response, error := sites.CreateVariable( + "", + "", + "", + appwrite.WithCreateVariableSecret(false), +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Sites; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let sites = Sites::new(&client); + + let result = sites.create_variable( + "", + "", + "", + Some(false) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## List variables {% #list-variables %} + +{% multicode %} +```server-nodejs +import { Client, Sites } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.listVariables({ + siteId: '' +}); +``` +```server-deno +import { Client, Sites } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.listVariables({ + siteId: '' +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$sites = new Sites($client); + +$result = $sites->listVariables( + siteId: '' +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.sites import Sites +from appwrite.models import VariableList + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +sites = Sites(client) + +result: VariableList = sites.list_variables( + site_id = '' +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +sites = Sites.new(client) + +result = sites.list_variables( + site_id: '' +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Sites sites = new Sites(client); + +VariableList result = await sites.ListVariables( + siteId: "" +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Sites sites = Sites(client); + +VariableList result = await sites.listVariables( + siteId: '', +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Sites + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val sites = Sites(client) + +val response = sites.listVariables( + siteId = "" +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Sites; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Sites sites = new Sites(client); + +sites.listVariables( + "", // siteId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let sites = Sites(client) + +let variableList = try await sites.listVariables( + siteId: "" +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +sites := appwrite.NewSites(client) + +response, error := sites.ListVariables( + "", +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Sites; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let sites = Sites::new(&client); + + let result = sites.list_variables( + "" + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Get a variable {% #get-variable %} + +{% multicode %} +```server-nodejs +import { Client, Sites } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.getVariable({ + siteId: '', + variableId: '' +}); +``` +```server-deno +import { Client, Sites } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.getVariable({ + siteId: '', + variableId: '' +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$sites = new Sites($client); + +$result = $sites->getVariable( + siteId: '', + variableId: '' +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.sites import Sites +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +sites = Sites(client) + +result: Variable = sites.get_variable( + site_id = '', + variable_id = '' +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +sites = Sites.new(client) + +result = sites.get_variable( + site_id: '', + variable_id: '' +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Sites sites = new Sites(client); + +Variable result = await sites.GetVariable( + siteId: "", + variableId: "" +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Sites sites = Sites(client); + +Variable result = await sites.getVariable( + siteId: '', + variableId: '', +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Sites + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val sites = Sites(client) + +val response = sites.getVariable( + siteId = "", + variableId = "" +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Sites; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Sites sites = new Sites(client); + +sites.getVariable( + "", // siteId + "", // variableId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let sites = Sites(client) + +let variable = try await sites.getVariable( + siteId: "", + variableId: "" +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +sites := appwrite.NewSites(client) + +response, error := sites.GetVariable( + "", + "", +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Sites; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let sites = Sites::new(&client); + + let result = sites.get_variable( + "", + "" + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Update a variable {% #update-variable %} + +You can change a variable's `key`, `value`, or `secret` flag. Marking a variable as secret is one-way. Once set, the value is no longer readable from the Console or API. + +{% multicode %} +```server-nodejs +import { Client, Sites } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.updateVariable({ + siteId: '', + variableId: '', + key: '', + value: '', // optional + secret: false // optional +}); +``` +```server-deno +import { Client, Sites } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.updateVariable({ + siteId: '', + variableId: '', + key: '', + value: '', // optional + secret: false // optional +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$sites = new Sites($client); + +$result = $sites->updateVariable( + siteId: '', + variableId: '', + key: '', + value: '', // optional + secret: false // optional +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.sites import Sites +from appwrite.models import Variable + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +sites = Sites(client) + +result: Variable = sites.update_variable( + site_id = '', + variable_id = '', + key = '', + value = '', # optional + secret = False # optional +) + +print(result.model_dump()) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +sites = Sites.new(client) + +result = sites.update_variable( + site_id: '', + variable_id: '', + key: '', + value: '', # optional + secret: false # optional +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Sites sites = new Sites(client); + +Variable result = await sites.UpdateVariable( + siteId: "", + variableId: "", + key: "", + value: "", // optional + secret: false // optional +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Sites sites = Sites(client); + +Variable result = await sites.updateVariable( + siteId: '', + variableId: '', + key: '', + value: '', // (optional) + secret: false, // (optional) +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Sites + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val sites = Sites(client) + +val response = sites.updateVariable( + siteId = "", + variableId = "", + key = "", + value = "", // optional + secret = false // optional +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Sites; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Sites sites = new Sites(client); + +sites.updateVariable( + "", // siteId + "", // variableId + "", // key + "", // value (optional) + false, // secret (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let sites = Sites(client) + +let variable = try await sites.updateVariable( + siteId: "", + variableId: "", + key: "", + value: "", // optional + secret: false // optional +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +sites := appwrite.NewSites(client) + +response, error := sites.UpdateVariable( + "", + "", + "", + appwrite.WithUpdateVariableValue(""), + appwrite.WithUpdateVariableSecret(false), +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Sites; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let sites = Sites::new(&client); + + let result = sites.update_variable( + "", + "", + "", + Some(""), // optional + Some(false) // optional + ).await?; + + let _ = result; + + Ok(()) +} +``` +{% /multicode %} + +## Delete a variable {% #delete-variable %} + +{% multicode %} +```server-nodejs +import { Client, Sites } from 'node-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.deleteVariable({ + siteId: '', + variableId: '' +}); +``` +```server-deno +import { Client, Sites } from "npm:node-appwrite"; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +const sites = new Sites(client); + +const result = await sites.deleteVariable({ + siteId: '', + variableId: '' +}); +``` +```server-php +setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + ->setProject('') // Your project ID + ->setKey(''); // Your API key + +$sites = new Sites($client); + +$result = $sites->deleteVariable( + siteId: '', + variableId: '' +); +``` +```server-python +from appwrite.client import Client +from appwrite.services.sites import Sites + +client = Client() +client.set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint +client.set_project('') # Your project ID +client.set_key('') # Your API key + +sites = Sites(client) + +result = sites.delete_variable( + site_id = '', + variable_id = '' +) +``` +```server-ruby +require 'appwrite' + +include Appwrite + +client = Client.new + .set_endpoint('https://.cloud.appwrite.io/v1') # Your API Endpoint + .set_project('') # Your project ID + .set_key('') # Your API key + +sites = Sites.new(client) + +result = sites.delete_variable( + site_id: '', + variable_id: '' +) +``` +```server-dotnet +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndPoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your API key + +Sites sites = new Sites(client); + +await sites.DeleteVariable( + siteId: "", + variableId: "" +); +``` +```server-dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your API key + +Sites sites = Sites(client); + +await sites.deleteVariable( + siteId: '', + variableId: '', +); +``` +```server-kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Sites + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +val sites = Sites(client) + +val response = sites.deleteVariable( + siteId = "", + variableId = "" +) +``` +```server-java +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Sites; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your API key + +Sites sites = new Sites(client); + +sites.deleteVariable( + "", // siteId + "", // variableId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); +``` +```server-swift +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your API key + +let sites = Sites(client) + +let result = try await sites.deleteVariable( + siteId: "", + variableId: "" +) +``` +```server-go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/appwrite" +) + +client := appwrite.NewClient( + appwrite.WithEndpoint("https://.cloud.appwrite.io/v1"), + appwrite.WithProject(""), + appwrite.WithKey(""), +) + +sites := appwrite.NewSites(client) + +response, error := sites.DeleteVariable( + "", + "", +) +``` +```server-rust +use appwrite::Client; +use appwrite::services::Sites; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + client.set_endpoint("https://.cloud.appwrite.io/v1"); // Your API Endpoint + client.set_project(""); // Your project ID + client.set_key(""); // Your API key + + let sites = Sites::new(&client); + + sites.delete_variable( + "", + "" + ).await?; + + Ok(()) +} +``` +{% /multicode %} + +# Read variables in your site {% #read-variables %} + +Read variables inside your site using your framework's standard environment lookup. For SSR sites, variables are read at runtime; for static sites, variables marked for build are inlined at build time. + +For framework-specific guidance such as Next.js, SvelteKit, or Astro, see the [framework adapters](/docs/products/sites/frameworks). + +# Appwrite-injected variables {% #appwrite-variables %} + +Appwrite passes the following environment variables into every site deployment by default. They take precedence over your own variables, so do not set keys with the `APPWRITE_` prefix. + +{% partial file="sites-env-vars.md" /%} + +# Secret variables {% #secret-variables %} + +Mark a variable as **Secret** to hide its value from the Console and API after creation. Only the site runtime can read the value at build and runtime. Team members and external integrations cannot retrieve it after creation. + +You can mark a variable as secret either when you create it or by updating an existing variable. Marking a variable as secret cannot be reversed. To replace a secret value, delete the variable and create a new one with the same key. + +# Limits {% #limits %} + +| Field | Limit | +|----------------|------------------------------------------------| +| Variable ID | 36 characters, `a-z A-Z 0-9 . - _` | +| Key | 255 characters | +| Value | 8192 characters | +| Reserved keys | Any key starting with `APPWRITE_` is reserved | diff --git a/static/images/docs/functions/dark/env-variables.png b/static/images/docs/functions/dark/env-variables.png new file mode 100644 index 0000000000..0ca5098c32 Binary files /dev/null and b/static/images/docs/functions/dark/env-variables.png differ diff --git a/static/images/docs/functions/env-variables.png b/static/images/docs/functions/env-variables.png new file mode 100644 index 0000000000..c4bcdd17fd Binary files /dev/null and b/static/images/docs/functions/env-variables.png differ diff --git a/static/images/docs/platform/dark/env-variables.png b/static/images/docs/platform/dark/env-variables.png new file mode 100644 index 0000000000..e90daea3c6 Binary files /dev/null and b/static/images/docs/platform/dark/env-variables.png differ diff --git a/static/images/docs/platform/env-variables.png b/static/images/docs/platform/env-variables.png new file mode 100644 index 0000000000..cf4e6d5acc Binary files /dev/null and b/static/images/docs/platform/env-variables.png differ