Sync Supabase contacts to Publiq

Keep Publiq contacts in sync with your Supabase users table to use attributes as variables.

In an Edge Function triggered by table changes, upsert the contact:

import { Publiq } from 'npm:publiq';
const publiq = new Publiq(Deno.env.get('PUBLIQ_API_KEY'));

Deno.serve(async (req) => {
  const { record } = await req.json();
  await publiq.contacts.create({
    email: record.email,
    attributes: { first_name: record.name, plan: record.plan },
  });
  return new Response('ok');
});

Best practices

  • Always call Publiq from the server — never expose the API key on the client.
  • Create the client instance once and reuse it across requests.
  • Prefer templateKey over inline HTML to keep content versioned.
  • Handle PubliqError (status/code); the SDK already retries transient errors with backoff.
  • Send from a verified domain — see Domains.

See also

Sync Supabase contacts to Publiq — Publiq Docs