agentsclimarketplace

Klaviyo hello world

Skill jeremylongshore/claude-code-plugins-plus-skills/plugins/saas-packs/klaviyo-pack/skills/klaviyo-hello-world

'Create a minimal working Klaviyo example with real API calls.From its SKILL.md

Install
npx -y skills add jeremylongshore/claude-code-plugins-plus-skills --skill klaviyo-hello-world

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its file declares

Copied from the file, not written here

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

4.8 KB, ~1.1k tokens by cl100k_base, as published. Nobody here has run it

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: '[email protected]', 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

ErrorStatusCauseSolution
Duplicate profile409Email already existsUse createOrUpdateProfile instead
Invalid email format400Malformed emailValidate email before sending
Missing metric name400Empty metric objectAlways include metric.data.attributes.name
Unauthorized401Bad API keyCheck 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: '[email protected]' } } },
      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.

What ships with it: 2 files

5.2 KB alongside SKILL.md

references/

Keep looking

Skills are one crate of 326,144. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.