Skip to content
Skillv1.0.0

klaviyo-hello-world

Create a minimal working Klaviyo example with real API calls. Use when starting a new Klaviyo integration, testing your setup, or learning basic profile creation and event tracking patterns. Trigger w

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (skills/.curated/klaviyo-hello-world/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill klaviyo-hello-world. Copyright stays with the author (MIT).

Klaviyo Hello World

Overview

Minimal working example: create a profile, track an event, and query the result using the klaviyo-api Node.js SDK against a.klaviyo.com/api/*. This is the smoke test that proves your API key, SDK install, and network path all work end-to-end before you build anything real.

Prerequisites

  • Completed the klaviyo-install-auth setup so credentials are in place.
  • KLAVIYO_PRIVATE_KEY exported in your environment (a private API key with Profiles and Events scopes).
  • klaviyo-api installed in the project (npm install klaviyo-api).
  • tsx available to run the TypeScript file (npx tsx …).

Instructions

Write the code into a single hello-klaviyo.ts file, then run it with npx tsx hello-klaviyo.ts. The full script performs four things in order:

  1. Create a profileprofilesApi.createProfile(...) with a JSON:API payload. The essential skeleton:

    import { ApiKeySession, ProfilesApi, ProfileEnum } from 'klaviyo-api';
    
    const session = new ApiKeySession(process.env.KLAVIYO_PRIVATE_KEY!);
    const profilesApi = new ProfilesApi(session);
    
    const profile = await profilesApi.createProfile({
      data: {
        type: ProfileEnum.Profile,
        attributes: { email: 'hello@example.com', firstName: 'Hello', lastName: 'World' },
      },
    });
    console.log('Profile created:', profile.body.data.id);
  2. Track an eventeventsApi.createEvent(...) with a metric (created on first use) linked to the profile by email.

  3. Retrieve the profileprofilesApi.getProfiles({ filter: '...' }) to confirm the write landed.

  4. Run the combined scriptnpx tsx hello-klaviyo.ts.

For the complete step-by-step code (all payloads with camelCase and JSON:API detail), see the full walkthrough. For the single combined runnable script and variations, see worked examples.

Output

Running the combined script prints one line per operation. The profile ID is a 26-character ULID; Verified echoes the firstName read back from the API, proving the round trip succeeded:

Profile created: 01JXXXXXXXXXXXXXXXXXXXXXX
Event tracked successfully
Verified: Hello

Error Handling

Error Status Cause Solution
Duplicate profile 409 Email already exists Use createOrUpdateProfile instead
Invalid email format 400 Malformed email Validate email before sending
Missing metric name 400 Empty metric object Always include metric.data.attributes.name
Unauthorized 401 Bad API key Check KLAVIYO_PRIVATE_KEY env var

Examples

The canonical example is the single combined script that creates a profile, tracks an event, and reads the profile back — see the worked examples for the full file plus two common variations (idempotent upsert with createOrUpdateProfile, and a revenue event that sets value). The core shape of every call is the same JSON:API envelope:

await eventsApi.createEvent({
  data: {
    type: 'event',
    attributes: {
      metric: { data: { type: 'metric', attributes: { name: 'Hello World Test' } } },
      profile: { data: { type: 'profile', attributes: { email: 'hello@example.com' } } },
      properties: { source: 'hello-world' },
      time: new Date().toISOString(),
    },
  },
});

Key SDK Conventions

  • camelCase properties: The SDK uses firstName, phoneNumber, lastName (not snake_case)
  • JSON:API format: All payloads use { data: { type, attributes } } structure
  • Response body: Access via response.body.data (not response.data)
  • Profile identifiers: Use email, phoneNumber, or externalId to identify profiles

Resources

Next Steps

Proceed to klaviyo-local-dev-loop for development workflow setup, or klaviyo-core-workflow-a for profile and list management.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-klaviyo-hello-world/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-klaviyo-hello-world.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-klaviyo-hello-world",
  "kind": "skill",
  "name": "klaviyo-hello-world",
  "description": "Create a minimal working Klaviyo example with real API calls. Use when starting a new Klaviyo integration, testing your setup, or learning basic profile creation and event tracking patterns. Trigger with phrases like \"klaviyo hello world\", \"klaviyo example\", \"klaviyo quick start\", \"simple klaviyo code\", \"first klaviyo call\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding",
      "general_chat"
    ],
    "tags": [
      "skill-md",
      "saas",
      "klaviyo",
      "email-marketing",
      "cdp",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Create a minimal working Klaviyo example with real API calls. Use when starting a new Klaviyo integration, testing your setup, or learning basic profile creation and event tracking patterns. Trigger with phrases like \"klaviyo hello world\", \"klaviyo example\", \"klaviyo quick start\", \"simple klaviyo code\", \"first klaviyo call\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "skills/.curated/klaviyo-hello-world/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/skills/.curated/klaviyo-hello-world/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/skills/.curated/klaviyo-hello-world/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Write,",
      "Bash(npm:*),",
      "Bash(npx:*)"
    ],
    "license": "MIT"
  },
  "instructions": "# Klaviyo Hello World\n\n## Overview\n\nMinimal working example: create a profile, track an event, and query the result\nusing the `klaviyo-api` Node.js SDK against `a.klaviyo.com/api/*`. This is the\nsmoke test that proves your API key, SDK install, and network path all work\nend-to-end before you build anything real.\n\n## Prerequisites\n\n- Completed the `klaviyo-install-auth` setup so credentials are in place.\n- `KLAVIYO_PRIVATE_KEY` exported in your environment (a private API key with\n  Profiles and Events scopes).\n- `klaviyo-api` installed in the project (`npm install klaviyo-api`).\n- `tsx` availab",
  "cost": {
    "context_tokens": 1073
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-klaviyo-hello-world/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.