Use maxclicks in Replit
Connect your Replit project to customer records, events, and prepared campaigns in maxclicks. Store the key as a secret and make API requests from your server runtime.
Make a first request over HTTP
This request runs in server-side JavaScript and needs no maxclicks package. Set MAXCLICKS_API_KEY in your server's secret store, then confirm the returned space before making a write.
const apiKey = process.env.MAXCLICKS_API_KEY
if (!apiKey) throw new Error('Set MAXCLICKS_API_KEY first')
const response = await fetch('https://api.maxclicks.ai/v1/me', {
headers: { Authorization: `Bearer ${apiKey}` },
})
const result = await response.json()
if (!response.ok) throw new Error(result.error?.message ?? 'Request failed')
console.log(result.data.space)
For a runtime without process.env, use its server-side secret API. Keep the key out of browser bundles. Follow the API quickstart to sync a contact and send a prepared template.
The examples below use the Node SDK for application code and the CLI for terminal automation.
Get an API key
Create a key in the maxclicks app under Settings, Developers (https://app.maxclicks.ai/space/-/settings/developers). A key is scoped to one space and looks like max_.... The suppression endpoints are the only ones that need a key whose owner has admin permission on the space.
Store the key as a Secret
Open Secrets
In the Replit left sidebar, open the Secrets tool (the padlock icon).
Add the key
Add a secret named
MAXCLICKS_API_KEYwith yourmax_...value. Both the SDK and the CLI read this variable by default, so no key appears in your source.
Do not paste the key into a file or a Repl that is public or forked. Secrets are injected as environment variables at run time and are not committed.
Option 1: Node SDK
Use the SDK for application code. It ships TypeScript types, automatic pagination, typed errors, and bounded retries: 429 on all calls, and 5xx/transport failures for reads and keyed writes.
Install the SDK from the Replit Shell. Requires Node.js 18 or newer:
npm install maxclicks
Construct the client with no argument to read MAXCLICKS_API_KEY from the Secret, then call a method:
import { Maxclicks } from 'maxclicks'
const mc = new Maxclicks() // reads MAXCLICKS_API_KEY
const me = await mc.me()
console.log(me.space?.name)
const contact = await mc.records.upsert('students', {
email: '[email protected]',
firstName: 'Ada',
tags: ['beta'],
})
console.log(contact.id)
Pass options to the constructor to override defaults:
const mc = new Maxclicks({
apiKey: process.env.MAXCLICKS_API_KEY,
baseUrl: 'https://api.maxclicks.ai/v1',
timeoutMs: 60000,
maxRetries: 2,
})
On success a call returns the data directly. On failure it throws a typed error, one of the MaxclicksError subclasses. See the Node SDK reference for the full method list.
Option 2: CLI
Install the CLI from the Replit Shell:
npm install -g maxclicks-cli
maxclicks whoami
It prints JSON to stdout and errors to stderr for shell scripts and tools such as jq.
The CLI reads MAXCLICKS_API_KEY from the Secret. Confirm the key and its space with whoami, then run commands:
maxclicks schemas list --type contact
maxclicks records upsert students --data '{"email":"[email protected]","firstName":"Ada"}'
maxclicks events fire purchase-completed --data '{"eventId":"ord_1","amount":42}'
maxclicks api GET /schemas
--all requests list pages as a flat array, subject to the API's traversal limit; it does not guarantee a full workspace export. Run maxclicks <command> --help for options. See the CLI reference for every command.
Which to use
| Use | Choose |
|---|---|
| A first request without a maxclicks package | Direct HTTP |
| Application code with types and pagination helpers | Node SDK |
| Shell scripts and JSON pipelines | CLI |