Set an environment variable
const url = 'https://apibase.ecomweb.app/api/v1/stores/example/hosting/env/example';const options = { method: 'PUT', headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'}, body: '{"value":"example","target":"runtime"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request PUT \ --url https://apibase.ecomweb.app/api/v1/stores/example/hosting/env/example \ --header 'Content-Type: application/json' \ --header 'x-api-key: <x-api-key>' \ --data '{ "value": "example", "target": "runtime" }'Creates the variable or replaces its value. The value is encrypted and cannot be read back; the response returns the name, target and update time only. Running previews and production restart to pick up a runtime variable, and the next build uses a build variable. A name has upper case letters, digits and underscores, starts with a letter and has at most 64 characters. Names beginning with ECOMWEB_ or CLIENT_IP_, and SITE_URL, NODE_ENV, PORT and HOSTNAME, are reserved. A build variable must start with NEXT_PUBLIC_ and is readable in the browser. A value is at most 4 KB and a store has at most 50 variables. Needs the admin:store scope and a plan that includes Hosting.
Required scopes: admin:store
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The variable’s name, such as STRIPE_SECRET_KEY.
The store’s ref, as returned by GET /stores.
Request Bodyrequired
Section titled “Request Bodyrequired”object
The value, at most 4 KB. It is encrypted and never returned by any route.
runtime (default): read by the running storefront and previews. build: a NEXT_PUBLIC_ variable the build reads and that ends up in the browser.
Responses
Section titled “Responses”object
runtime: read by the running storefront. build: read while it is built.
When the variable was last set, as an ISO 8601 timestamp.
The variable’s name.
Example
{ "target": "runtime"}The request is malformed or failed validation.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key is missing, invalid, revoked or expired.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key may not do this: a missing scope, a readonly key, a publishable key on a Store API route, or a disallowed origin.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The resource does not exist in this store.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}