Create an endpoint with variables
Contents
This guide walks through creating an endpoint that accepts variables, allowing you to filter results at execution time. We'll create a customer-specific analytics endpoint that filters data by a customer_id property.
Step 1: Write your SQL query with a variable
Open the SQL editor and write a query that uses the {variables.variable_name} syntax:


Step 2: Define the variable
In the Variables tab in the output pane, click Add variable, then New variable and fill in the modal.
- Name: A human-readable name (e.g., "Customer ID")
- Type: The variable type (String, Number, etc.)
- Default value: Optional default when no value is provided


Step 3: Test your query
Enter a test value for your variable and run the query to verify it works:


Step 4: Create the endpoint
Once your query works, click the Endpoint tab in the output pane:
- Enter a descriptive name (e.g.,
customer_events_by_day) - Add an optional description
- Click Create endpoint


Step 5: Execute with a variable
Now you can call your endpoint and pass the variable value:
The response will only include events where properties.customer_id = 'acme-corp'.
Pay attention: Variables are required
If your endpoint has a variable defined, you must provide a value when executing. This is a safety feature to prevent accidentally returning unfiltered data.
Calling the endpoint without the required variable will return an error:
Next steps
- Learn more about variables including magic variables for insight-based endpoints
- Materialize your endpoint for better performance
- Generate a typed SDK from your endpoint's OpenAPI spec