Global Variables and Code Snippets
Global variables and code snippets are two small building blocks in the Developer area. Variables hold settings and keys your actions need, such as an API key for another service, so they aren't written into code. Code snippets hold reusable JavaScript, CSS, HTML or JSON that you can load from your websites and apps.
Global variables
A global variable is a named value stored in your organisation. Each variable has:
- Key — the name you use to look it up, for example
accountingApiKey. Keys must be unique within your organisation. - Data Type — Basic Text / String, Boolean, Number / Decimal, Integer / Whole Number, Email Address, URL, Date, Content Reference or Generic Object Literal.
- Reference Type — for a Content Reference, which kind of content it points to.
- Value — the value itself, checked against the data type.
When to use a variable
- API keys and credentials for services your actions call, such as an accounting system or a CRM.
- Settings that change, such as the email address that receives daily reports, or a threshold an action checks.
- A record your automations point to, such as "the current season's event", stored as a Content Reference so you can change it without editing code.
Creating a variable
- Click Developer in the sidebar.
- In the Global Variables panel, click View All, then create a new variable from the list page.
- Enter the Key, choose the Data Type and set the Value.
- Choose the scope it belongs to (see Permissions below) and save.
Using variables in actions
An action can read variables through its SDK by calling the /variables endpoint. It returns every variable the action is allowed to see, as an object of keys and values, for example { "accountingApiKey": "…", "reportRecipient": "office@acme.com" }. Because actions run on Qik's servers, the value never reaches a visitor's browser. See Actions.
Never put API keys or passwords in Custom Code blocks on your websites or apps. Custom Code is sent to every visitor's browser. Keep secrets in a variable and use them only from an action.
Permissions
Variables follow normal access rules. A person or action only sees the variables their roles allow in the scopes they have access to. For a secret, put the variable in a scope that only the action that needs it (and your administrators) can read, and give the action's role permission to view variables in that scope. The Developer menu item only appears for people whose role lets them see actions, listeners, time triggers, code snippets or variables.
Code snippets
A code snippet is a piece of code stored in Qik that can be loaded by its own web address. Each snippet has a Syntax (Javascript, CSS, CSS / SCSS, HTML or JSON) and a Body containing the code.
When to use a code snippet
- A shared stylesheet or script used by several websites or by pages hosted elsewhere.
- A JSON file of settings or reference data that a site or an external tool reads.
- An HTML fragment you want to keep and edit in one place.
Creating a code snippet
- Click Developer in the sidebar.
- In the Code Snippets panel, click New Code Snippet.
- Give it a title, then on the Code tab write or paste your code.
- On the Configuration tab, choose the Syntax.
- Save.
Loading a snippet
Each snippet is served at https://api.qik.dev/code/<snippet id> with the right file type for its syntax (for example as a stylesheet for CSS, or as a script for JavaScript). You can copy the id from the snippet's actions menu.
- Snippets with Security set to Secure (the default) can only be loaded by someone signed in who has permission to view them.
- Set Security to Public to load a snippet from a public website, for example in a
<link>or<script>tag. Anyone with the address can then read it, so never put secrets in a public snippet.
For styling and code inside a Qik website or app, you'll usually use the interface builder's own tools instead. See Using the Custom Code Block and How SCSS Works Inside the Builder.
Tips
- Use clear, consistent keys for variables, such as
stripeWebhookSecretorreportRecipient, so actions are easy to read. - Changing a variable's value takes effect the next time an action reads it. You don't need to edit or redeploy the action.
- Qikbot and connected AI tools treat creating and changing actions with care: running or testing an action always needs your approval in Qikbot.