Skip to content

Set an environment variable

PUT
/stores/{storeRef}/hosting/env/{name}
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

name
required
string

The variable’s name, such as STRIPE_SECRET_KEY.

storeRef
required
string

The store’s ref, as returned by GET /stores.

Media typeapplication/json
object
value
required

The value, at most 4 KB. It is encrypted and never returned by any route.

string
target

runtime (default): read by the running storefront and previews. build: a NEXT_PUBLIC_ variable the build reads and that ends up in the browser.

string
Allowed values: runtime build
Media typeapplication/json
object
target
required

runtime: read by the running storefront. build: read while it is built.

string
Allowed values: runtime build
updated_at
required

When the variable was last set, as an ISO 8601 timestamp.

string format: date-time
name
required

The variable’s name.

string

Example

{
"target": "runtime"
}

The request is malformed or failed validation.

Media typeapplication/json
One of:
object
statusCode
required

The HTTP status code.

number
message
required

What went wrong; validation failures list one message per problem.

One of:
string
error

The HTTP status text, such as Bad Request.

string

Example generated

{
"statusCode": 1,
"message": [
"example"
],
"error": "example"
}

The key is missing, invalid, revoked or expired.

Media typeapplication/json
One of:
object
statusCode
required

The HTTP status code.

number
message
required

What went wrong; validation failures list one message per problem.

One of:
string
error

The HTTP status text, such as Bad Request.

string

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.

Media typeapplication/json
One of:
object
statusCode
required

The HTTP status code.

number
message
required

What went wrong; validation failures list one message per problem.

One of:
string
error

The HTTP status text, such as Bad Request.

string

Example generated

{
"statusCode": 1,
"message": [
"example"
],
"error": "example"
}

The resource does not exist in this store.

Media typeapplication/json
One of:
object
statusCode
required

The HTTP status code.

number
message
required

What went wrong; validation failures list one message per problem.

One of:
string
error

The HTTP status text, such as Bad Request.

string

Example generated

{
"statusCode": 1,
"message": [
"example"
],
"error": "example"
}