### Quick Start Example Source: https://docs.creem.io/code/sdks/typescript-wrapper A basic example demonstrating how to use the creem_io TypeScript wrapper. ```typescript import { CreemIO } from "creem_io"; async function main() { const creem = new CreemIO({ // Configuration options // e.g., apiKey: "YOUR_API_KEY", // baseUrl: "https://api.creem.io/v1", }); try { // Example: Fetching data const response = await creem.get("/some-endpoint"); console.log("Data received:", response.data); // Example: Sending data const postResponse = await creem.post("/another-endpoint", { key: "value", }); console.log("Post response:", postResponse.data); } catch (error) { console.error("An error occurred:", error); } } main(); ``` -------------------------------- ### Quick Start TypeScript Example Source: https://docs.creem.io/code/sdks/typescript-wrapper A basic example demonstrating how to use the creem_io TypeScript wrapper. This snippet shows initialization and a simple API call. ```typescript import { CreemIO } from "creem_io"; const client = new CreemIO({ apiKey: "YOUR_API_KEY", // Other optional configurations }); async function main() { try { // Example: Fetching data const response = await client.someMethod({ // Parameters for the method param1: "value1", param2: 123, }); console.log("Success:", response); } catch (error) { console.error("Error:", error); } } main(); ``` -------------------------------- ### Get Product (creem) Source: https://docs.creem.io/code/sdks/migrate-from-creem-io Example of getting a product using the new creem SDK. ```javascript const product = await creem.products.get("prod_123"); ``` -------------------------------- ### Authentication Example Source: https://docs.creem.io/api-reference/introduction All API requests must include your API key in the `x-api-key` header. This example shows how to authenticate a GET request to the /products endpoint. ```APIDOC ## GET /v1/products ### Description Retrieves a list of products. This is an example endpoint to demonstrate authentication. ### Method GET ### Endpoint /v1/products ### Parameters #### Headers - **x-api-key** (string) - Required - Your Creem API key. ### Request Example ```bash curl -X GET https://api.creem.io/v1/products \ -H "x-api-key: creem_YOUR_API_KEY" ``` ### Response #### Success Response (200) - **(structure not provided)** - Description of the response body for a successful request. #### Response Example (Response example not provided in source) ``` -------------------------------- ### Creem IO Quick Start Example Source: https://docs.creem.io/llms-full.txt Initialize the creem_io client and perform basic operations like retrieving a product and creating a checkout session. Ensure API keys and webhook secrets are set in environment variables. ```typescript import { createCreem } from 'creem_io'; const creem = createCreem({ apiKey: process.env.CREEM_API_KEY!, webhookSecret: process.env.CREEM_WEBHOOK_SECRET, // optional, for webhooks testMode: false, // set to true for test mode }); // Retrieve a product const product = await creem.products.get({ productId: 'prod_7CIbZEZnRC5DWibmoOboOu', }); console.log(product); // Create a checkout session const checkout = await creem.checkouts.create({ productId: 'prod_xxxxx', successUrl: 'https://yourapp.com/success', metadata: { userId: 'user_123', }, }); console.log(checkout.checkoutUrl); // Redirect user to this URL ``` -------------------------------- ### Get Product (creem_io) Source: https://docs.creem.io/code/sdks/migrate-from-creem-io Example of getting a product using the older creem_io SDK. ```javascript const product = await creem.products.get({ productId: "prod_123", }); ``` -------------------------------- ### Start Development Server Source: https://docs.creem.io/llms-full.txt Start the Next.js development server to run the template locally. ```bash yarn dev ``` -------------------------------- ### Install Creem SDK Source: https://docs.creem.io/features/checkout/checkout-api Instructions on how to install the Creem SDK using yarn, pnpm, or bun. ```APIDOC ## Install Creem SDK This section provides instructions for installing the Creem SDK using different package managers. ### Yarn ```shell yarn add creem ``` ### pnpm ```shell pnpm install creem ``` ### bun ```shell bun install creem ``` ``` -------------------------------- ### Fetch Heartbeat Guide Source: https://docs.creem.io/ai/for-agents/skill-files Use this command to fetch the heartbeat guide from the specified URL. ```shellscript # Fetch the heartbeat guide curl -s https://creem.io/HEARTBEAT.md ``` -------------------------------- ### Express Webhook Setup Source: https://docs.creem.io/code/sdks/typescript-wrapper Example of setting up an Express.js endpoint to receive JSON webhooks. Ensure you have the 'express' package installed. ```typescript import express from "express"; app.post("/webhook", express.raw({ type: "application/json" }), async () => { }); ``` -------------------------------- ### Get Products Request Example Source: https://docs.creem.io/api-reference/error-codes Example of how to make a GET request to the products endpoint using curl. Ensure you replace 'creem_YOUR_API_KEY' with your actual API key. ```bash curl -X GET https://api.creem.io/v1/products \ -H "x-api-key: creem_YOUR_API_KEY" ``` -------------------------------- ### Manage Plugin (Commented Example) Source: https://docs.creem.io/code/sdks/ai-agents This is a commented-out example showing how to manage plugins. It is not executable as is and serves as a reference for potential commands or configurations. ```shellscript # -------------------------------------------------------------------------- # Plugin Management # -------------------------------------------------------------------------- # List all installed plugins # /plugin list # Uninstall a plugin # /plugin uninstall # Update a plugin # /plugin update # Show plugin details # /plugin info # Enable/disable a plugin # /plugin enable # /plugin disable # Search for plugins # /plugin search # Add a plugin from a specific URL or repository # /plugin add # Clear plugin cache # /plugin cache clear ``` -------------------------------- ### Client Configuration Example Source: https://docs.creem.io/code/sdks/better-auth Set up the client-side authentication client, importing necessary functions from the SDK. ```typescript // lib/auth-client.ts import { createAuthClient } from 'better-auth/react'; import { creemClient } from ``` -------------------------------- ### Set Up Environment Variables Source: https://docs.creem.io/llms-full.txt Copy the example environment file and fill in the required variables for your Creem integration. ```bash cp .env.example .env # Edit .env and fill in the required variables ``` -------------------------------- ### Activate License Example Source: https://docs.creem.io/api-reference/endpoint/validate-license Demonstrates how to activate a license using the API. Ensure you have the correct license key and product ID. ```javascript activateLicense: \ ``` -------------------------------- ### Example Usage in creem_io SDK Source: https://docs.creem.io/code/sdks/migrate-from-creem-io This TypeScript example demonstrates how to use the older creem_io SDK to get a product. ```typescript const product = creem_io.products.get({ productId: "prod_123" }) ``` -------------------------------- ### Create Product Source: https://docs.creem.io/ai/for-humans/cli Create a new product with specified details like name, price, and billing. ```bash creem products create --name "Pro Plan" --price 1999 --currency USD --billing-type recurring --billing-period every-month ``` -------------------------------- ### List, Get, Create, and Search Products Source: https://docs.creem.io/code/sdks/typescript Demonstrates how to list, retrieve, create, and search for products using the SDK. Ensure you have the necessary product details for creation. ```typescript // List products const productPage = await creem.products.search(1, 10); const products = productPage.result.items; // Get a product const product = await creem.products.get("prod_7CIbb..."); // Create a product const createdProduct = await creem.products.create({ name: "Test Product", description: "Test Product Description", price: 1000, // In cents currency: "USD", billingType: "recurring", billingPeriod: "every-month", }); // Search products const productsPage = await creem.products.search(1, 10); console.log(productsPage.result.items); ``` -------------------------------- ### Install and Authenticate Creem CLI Source: https://creem.io/HEARTBEAT Install the Creem CLI using Homebrew and authenticate with your API key. This is the recommended setup for agents with shell access. ```bash brew tap armitage-labs/creem && brew install creem creem login --api-key creem_THEIR_KEY_HERE ``` -------------------------------- ### Create a Product (CLI) Source: https://creem.io/SKILL Use the CLI to create a new product, specifying its name, description, price, currency, and billing details for one-time or recurring purchases. ```bash # CLI creem products create \ --name "Pro Plan" \ --description "Monthly pro subscription with all features" \ --price 1999 \ --currency USD \ --billing-type recurring \ --billing-period every-month \ --tax-category saas ``` -------------------------------- ### Save Heartbeat Guide and Initialize State File Source: https://creem.io/SKILL Saves the heartbeat guide locally and initializes the state file for monitoring. Ensure you have the Creem CLI installed or API access. ```bash # Save the heartbeat guide locally mkdir -p ~/.creem/skills curl -s https://creem.io/HEARTBEAT.md > ~/.creem/skills/HEARTBEAT.md # Initialize the state file mkdir -p ~/.creem cat > ~/.creem/heartbeat-state.json << 'EOF' { "lastCheckAt": null, "lastTransactionId": null, "transactionCount": 0, "customerCount": 0, "subscriptions": { "active": 0, "trialing": 0, "past_due": 0, "paused": 0, "canceled": 0, "expired": 0, "scheduled_cancel": 0 }, "knownSubscriptions": {} } EOF ``` -------------------------------- ### List Products with TypeScript SDK Source: https://docs.creem.io/code/sdks/typescript Demonstrates how to list products using the SDK. Ensure the SDK is initialized with your API key. ```typescript // List products const productPage = await creem ``` -------------------------------- ### Checkout Success Page GET Request Handler Source: https://docs.creem.io/features/checkout An example of an asynchronous GET request handler for a checkout success page. It demonstrates how to construct a URL and potentially fetch data related to the request. ```typescript export async function GET(request: Request) { const url = new URL(request); // ... rest of the handler logic ... } ``` -------------------------------- ### Example Search Request Source: https://docs.creem.io/api-reference/endpoint/search-products Demonstrates how to construct a search query for products. This example shows a basic query with a search term and pagination parameters. ```javascript const searchProducts = async (searchTerm, page = 1, limit = 10) => { try { const response = await fetch(`/api/products/search?q=${encodeURIComponent(searchTerm)}&page=${page}&limit=${limit}`); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error('Error searching products:', error); return null; } }; // Example usage: searchProducts('example product', 1, 5).then(results => { if (results) { console.log('Search Results:', results); } }); ``` -------------------------------- ### TypeScript Function for GET Request Source: https://docs.creem.io/features/checkout/checkout-api Example of an asynchronous TypeScript function to handle GET requests, often used for fetching checkout status or details. It constructs a URL and prepares to read redirect parameters. ```typescript export async function GET(request: Request) { const url = new URL(request.url); // Read fields in the order they appear in the redirect URL. const params: RedirectParams = { ``` -------------------------------- ### Next.js Client Component Integration Source: https://docs.creem.io/features/checkout Example of integrating CreemCheckout into a Next.js client component. Ensure you have the '@creem_io/nextjs' package installed. ```javascript "use client"; import { CreemCheckout } from "@creem_io/nextjs"; export function CheckoutButton() { return ( ); } ``` -------------------------------- ### Retrieve a Product Source: https://docs.creem.io/code/sdks/typescript Fetch a specific product using its ID. This example demonstrates how to call the `get` method on the `products` object. ```typescript // Retrieve a product const product = await creem.products.get("prod_7CIbZEZnRC5DWibmoOboOu"); console.log(product); ``` -------------------------------- ### OpenAPI Configuration Examples Source: https://docs.creem.io/llms-full.txt Demonstrates how to configure OpenAPI file paths. Supports single URLs, relative paths, or multiple OpenAPI definitions. ```json "openapi": "https://example.com/openapi.json" ``` ```json "openapi": "/openapi.json" ``` ```json "openapi": ["https://example.com/openapi1.json", "/openapi2.json", "/openapi3.json"] ``` -------------------------------- ### List Products Source: https://docs.creem.io/ai/for-humans/cli Use this command to list all available products. ```bash creem products list ``` -------------------------------- ### REST API - Get Products Source: https://creem.io/ This example shows how to retrieve a list of available products using the Creem REST API. ```APIDOC ## REST API - Get Products ### Description Retrieves a list of all available products from the Creem platform. ### Method GET ### Endpoint `/v1/products` ### Parameters None ### Request Example ```bash curl -X GET /v1/products ``` ### Response #### Success Response (200 OK) Returns a JSON array of product objects. ``` -------------------------------- ### Get Product by ID Source: https://docs.creem.io/code/sdks/migrate-from-creem-io Example of fetching a product using its ID. This snippet demonstrates the basic syntax for retrieving product information. ```typescript const product = await creem.products.get({"productId": "prod_123"}); ``` -------------------------------- ### Create a Discount Code Source: https://docs.creem.io/code/sdks/typescript This example demonstrates how to create a new discount code using the SDK. Provide the necessary details for the discount code. ```typescript // Create a discount code const discount = await creem.discounts.create({ key: "discount_key_here", instanceId: "inst_abc123", }); ``` -------------------------------- ### Common Error Codes Source: https://docs.creem.io/api-reference/error-codes This snippet shows examples of common error codes and their associated messages. Use the trace ID to get more help. ```json { "trace_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "error_code": "INVALID_PRODUCT_ID", "message": "Product ID is invalid." } HTTP Status: %{http_code} ``` -------------------------------- ### Example Usage of Better Auth SDK Source: https://docs.creem.io/code/sdks/better-auth This snippet demonstrates how to initialize and use the Better Auth SDK, including setting up authentication and subscription persistence. ```javascript function MDXContent(props = {}) { const {wrapper: MDXLayout} = { ... }; return MDXLayout ? _jsx(MDXLayout, { ... }) : _createMdxContent(props); } return { default: MDXContent }; function _missingMdxReference(id, component) { throw new Error("Expected " + (component ? "component" : "object") + ``` -------------------------------- ### Server Configuration Example Source: https://docs.creem.io/code/sdks/better-auth Configure server-side authentication settings, including the default success URL and subscription persistence. ```typescript import { createAuthServer } from 'better-auth'; const authServer = createAuthServer({ // Redirect URL after payments defaultSuccessUrl: '/success', // Enable database persistence (recommended) persistSubscriptions: true, }); ``` -------------------------------- ### Create a Checkout Source: https://docs.creem.io/features/checkout/checkout-api Creates a new checkout instance using the auth client. This example demonstrates the basic setup for initiating a checkout process. ```typescript "use client"; import { authClient } from "./auth"; const checkout = await authClient.checkout.create({ amount: 1000, currency: "USD", items: [ { name: "T-Shirt", quantity: 1, price: 1000, }, ], }); ``` -------------------------------- ### Nuxt Creem Module Setup Source: https://docs.creem.io/code/community/nuxt-creem This snippet shows the basic structure for integrating the Nuxt Creem module. Ensure you have Nuxt.js installed and configured. ```javascript import { defineNuxtModule } from 'nuxt/kit' export default defineNuxtModule({ meta: { name: 'nuxt-creem', configKey: 'creem' }, defaults: { // module options }, setup (options, nuxt) { // nuxt.options.build.transpile.push('creem') } }) ``` -------------------------------- ### Create Product and Accept Payments via CLI Source: https://docs.creem.io/ This snippet demonstrates how to create a product and set up payment acceptance using the Creem CLI. It involves multiple steps to configure pricing and checkout. ```shellscript creem product create --name "My Awesome Product" --price 10.00 --currency USD creem checkout create --product-id "prod_123" --success-url "https://example.com/success" --cancel-url "https://example.com/cancel" ``` -------------------------------- ### Initialize Heartbeat State File Source: https://docs.creem.io/ai/for-agents/skill-files Initialize the heartbeat state file with default values. This is a one-time setup required before starting store monitoring. ```bash # Initialize state file cat > ~/.creem/heartbeat-state.json << 'EOF' { "lastCheckAt": null, "lastTransactionId": null, "transactionCount": 0, "customerCount": 0, "subscriptions": { "active": 0, "trialing": 0, "past_due": 0, "paused": 0, "canceled": 0, "expired": 0, "scheduled_cancel": 0 }, "knownSubscriptions": {} } EOF ``` -------------------------------- ### Create Your First Product Source: https://docs.creem.io/code/sdks/migrate-from-creem-io Step-by-step guide to creating and sharing your first product on Creem ```APIDOC ## Create Your First Product ### Description Step-by-step guide to creating and sharing your first product on Creem ### Endpoint /guides/create-your-first-product ``` -------------------------------- ### Customer Portal Route Handler Source: https://docs.creem.io/features/customer-portal Example of a Next.js route handler for the customer portal. It imports the Portal component and exports a GET request handler. ```typescript // app/portal/route.ts import { Portal } from "@creem_io/nextjs"; export const GET = ( apiKey: process.env.CREEM_API_KEY!, testMode: process.env.NODE_ENV ) ``` -------------------------------- ### Basic Creem Adapter Setup in Next.js Source: https://docs.creem.io/code/sdks/nextjs This snippet shows how to set up the Creem adapter within a Next.js application. Ensure you have the necessary dependencies installed. ```javascript import { CreemNextJsAdapter } from "@creem/nextjs-adapter"; const adapter = new CreemNextJsAdapter({ apiKey: process.env.CREEM_API_KEY, webhookSecret: process.env.CREEM_WEBHOOK_SECRET, testMode: process.env.NODE_ENV !== "production", }); export default adapter.createHandler(); ``` -------------------------------- ### Create a New Product Source: https://docs.creem.io/llms-full.txt Creates a new product with specified details including name, description, price, currency, and billing information. Ensure all required fields are provided. ```bash # Create a product creem products create \ --name "Pro Plan" \ --description "Monthly pro subscription with all features" \ --price 1999 \ --currency USD \ --billing-type recurring \ --billing-period every-month ``` -------------------------------- ### Initialize AI Agent Source: https://docs.creem.io/code/sdks/ai-agents Demonstrates how to initialize an AI agent with a license key and instance name. Ensure you have the necessary credentials before use. ```javascript const agent = new Agent({ licenseKey: licenseKey, instanceName: instanceName }); ``` -------------------------------- ### Add a Checkout Button Source: https://docs.creem.io/features/checkout/checkout-api This example demonstrates how to import and use the CreemCheckout component to create a checkout button in a Next.js application. Ensure you have the '@creem_io/nextjs' package installed. ```tsx // app/page.tsx "use client"; // Optional: CreemCheckout also works in Server Components import { CreemCheckout } from "@creem_io/nextjs"; export function CheckoutButton() { return ( ); } ``` -------------------------------- ### List Customers with TypeScript SDK Source: https://docs.creem.io/code/sdks/typescript This example demonstrates how to list customers using the Creem TypeScript SDK. It's a starting point for customer data retrieval. ```typescript // List customers const customerPage ``` -------------------------------- ### Handle Success Page Request Source: https://docs.creem.io/features/checkout/checkout-api This example shows how to handle a GET request on your success page. It constructs a URL object from the request and is intended for further processing of successful checkout details. ```typescript export async function GET(request: Request) { const url = new URL(request.url) // Further processing of checkout details from the URL return new Response('Success page loaded', { status: 200, }) } ``` -------------------------------- ### Example Checkout Configuration Source: https://docs.creem.io/features/checkout/checkout-api This snippet shows how to configure checkout parameters, including product ID and success URL. It also includes a basic button element for initiating the checkout. ```jsx _jsx(_components.span, {\n style: {\n color: \"#0A3069\",\n \"--shiki-dark\": \"#CE9178\"\n },\n children: \"\\\"prod_YOUR_PRODUCT_ID\\\"\"\n })], \"\\n\", _jsxs(_components.span, {\n className: \"line\",\n children: [\n _jsx(_components.span, {\n style: {\n color: \"#0550AE\",\n \"--shiki-dark\": \"#9CDCFE\"\n },\n children: \" successUrl\"\n }), _jsx(_components.span, {\n style: {\n color: \"#CF222E\",\n \"--shiki-dark\": \"#D4D4D4\"\n },\n children: \"=\"\n }), _jsx(_components.span, {\n style: {\n color: \"#0A3069\",\n \"--shiki-dark\": \"#CE9178\"\n },\n children: \"\\\"/account/welcome\\\"\"\n }), _jsx(_components.span, {\n style: {\n color: \"#6E7781\",\n \"--shiki-dark\": \"#6A9955\"\n },\n children: \" // Overrides defaultSuccessUrl\"\n }) ]\n }), \"\\n\", _jsx(_components.span, {\n className: \"line\",\n children: _jsx(_components.span, {\n style: {\n color: \"#1F2328\",\n \"--shiki-dark\": \"#808080\"\n },\n children: \"\u003e\"\n })\n }), \"\\n\", _jsxs(_components.span, {\n className: \"line\",\n children: [\n _jsx(_components.span, {\n style: {\n color: \"#1F2328\",\n \"--shiki-dark\": \"#808080\"\n },\n children: \" \u003c\"\n }), _jsx(_components.span, {\n style: {\n color: \"#116329\",\n \"--shiki-dark\": \"#569CD6\"\n },\n children: \"button\"\n }), _jsx(_components.span, {\n style: {\n color: \"#1F2328\",\n \"--shiki-dark\": \"#808080\"\n },\n children: \"\u003e\"\n }), _jsx(_components.span, {\n style: {\n color: \"#1F2328\",\n \"--shiki-dark\": \"#D4D4D4\"\n },\n children: \"Get Started\"\n }), _jsx(_components.span, {\n style: {\n color: \"#1F2328\",\n \"--shiki-dark\": \"#808080\"\n },\n children: \"\u003c/\"\n }), _jsx(_components.span, {\n style: {\n color: \"#116329\",\n \"--shiki-dark\": \"#569CD6\"\n },\n children: \"button\"\n }), _jsx(_components.span, {\n style: {\n color: \"#1F2328\",\n \"--shiki-dark\": \"#808080\"\n },\n children: \"\u003e\"\n }) ]\n }), \"\\n\", _jsxs(_components.span, {\n className: \"line\",\n children: [\n _jsx(_components.span, {\n style: {\n color: \"#1F2328\",\n \"--shiki-dark\": \"#808080\"\n },\n children: \"\u003c/\"\n }), _jsx(_components.span, {\n style: {\n color: \"#116329\",\n \"--shiki-dark\": \"#4EC9B0\"\n },\n children: \"CreemCheckout\"\n }), _jsx(_components.span, {\n style: {\n color: \"#1F2328\",\n \"--shiki-dark\": \"#808080\"\n },\n children: \"\u003e\"\n }) ]\n }), \"\\n\" ]\n })\n })\n })\n })\n }) ``` -------------------------------- ### Get Customer by Email using TypeScript Wrapper Source: https://docs.creem.io/code/sdks/typescript-wrapper This example shows how to fetch customer details by providing their email address. It's useful for looking up customers when an ID is not readily available. ```typescript const customerByEmail = await creem.customers.get({ email: 'customer@example.com', }); ``` -------------------------------- ### Prompt AI for Development Assistance Source: https://docs.creem.io/code/sdks/ai-agents After installing the necessary skills, you can ask Claude to help with development tasks by providing a clear prompt. This example shows how to request help with creating a checkout flow. ```text Help me create a checkout flow for my SaaS product ```