### Install Dependencies Source: https://docs.lemonsqueezy.com/guides/tutorials/in-app-purchases Install the necessary Express and LemonSqueezy JavaScript SDK packages using npm. ```bash npm install express @lemonsqueezy/lemonsqueezy.js ``` -------------------------------- ### Create Checkout with API (cURL Example) Source: https://docs.lemonsqueezy.com/guides/developer-guide/taking-payments Example using cURL to create a checkout via the Lemon Squeezy API, demonstrating how to include checkout data. ```bash curl -X "POST" "https://api.lemonsqueezy.com/v1/checkouts" \ -H 'Accept: application/vnd.api+json' \ -H 'Content-Type: application/vnd.api+json' \ -H 'Authorization: Bearer {api_key}' \ -d '{...}' ``` -------------------------------- ### Example Product Response with Variant Relationships Source: https://docs.lemonsqueezy.com/guides/tutorials/api-related-resources This is an example response from the `/products` endpoint, illustrating the structure of product data and the `relationships.variants.links` object, which can be used to query variant data. ```json { "data": [ { "type": "products", "id": "1", "attributes": { "store_id": 1, "name": "Example Product", "slug": "example-product", "description": "

Lorem ipsum...

", "status": "published", "status_formatted": "Published", "thumb_url": "https://app.lemonsqueezy.com/storage/media/1/1c40f227-aed5-4321-9ffc-62f37a06c9a0.jpg", "large_thumb_url": "https://app.lemonsqueezy.com/storage/media/1/1c40f227-aed5-4321-9ffc-62f37a06c9a0.jpg", "price": 999, "price_formatted": "$9.99", "from_price": null, "to_price": null, "pay_what_you_want": false, "buy_now_url": "https://my-store.lemonsqueezy.com/checkout/buy/0a841cf5-4cc2-4bbb-ae5d-9529d97deec6", "created_at": "2021-05-27T12:54:47.000000Z", "updated_at": "2021-07-14T11:25:24.000000Z", "test_mode": false }, "relationships": { "store": { "links": { "related": "https://api.lemonsqueezy.com/v1/products/1/store", "self": "https://api.lemonsqueezy.com/v1/products/1/relationships/store" } }, "variants": { "links": { "related": "https://api.lemonsqueezy.com/v1/products/1/variants", "self": "https://api.lemonsqueezy.com/v1/products/1/relationships/variants" } } }, "links": { "self": "https://api.lemonsqueezy.com/v1/products/1" } }, {...}, {...} ] ... ``` -------------------------------- ### Example Basic Checkout Link Source: https://docs.lemonsqueezy.com/help/checkout/prefilled-checkout-fields An example of a complete, basic checkout link for a specific product variant. ```text https://my-store.lemonsqueezy.com/checkout/buy/d1f120fd-5adc-4fff-8915-cce713d29427 ``` -------------------------------- ### Example Basic Checkout Link Source: https://docs.lemonsqueezy.com/help/checkout/prefilling-checkout-fields An example of a complete, basic checkout link for a specific product variant. ```text https://my-store.lemonsqueezy.com/checkout/buy/d1f120fd-5adc-4fff-8915-cce713d29427 ``` -------------------------------- ### Default Affiliate URL Example Source: https://docs.lemonsqueezy.com/help/affiliates-for-merchants/getting-referrals This is an example of a default affiliate URL pointing to a Lemon Squeezy storefront. ```text https://my-store.lemonsqueezy.com/?aff=1234 ``` -------------------------------- ### Setup Event Handler for Lemon.js Source: https://docs.lemonsqueezy.com/guides/developer-guide/lemonjs Listen for events during the overlay form flow by specifying an 'eventHandler' in LemonSqueezy.Setup(). ```javascript LemonSqueezy.Setup({ eventHandler: (data) => { if (data.event == "PaymentMethodUpdate.Updated") { // Do something when the payment method has been updated } } }); ``` -------------------------------- ### Create Checkout API Request Example Source: https://docs.lemonsqueezy.com/help/checkout/prefilling-checkout-fields Example cURL command to create a checkout via the API, including pre-filled customer data in the request body. Ensure correct headers and authorization are used. ```bash curl -X "POST" "https://api.lemonsqueezy.com/v1/checkouts" \ -H 'Accept: application/vnd.api+json' \ -H 'Content-Type: application/vnd.api+json' \ -H 'Authorization: Bearer {api_key}' \ -d '{ "data": { "type": "checkouts", "attributes": { "checkout_data": { "email": "johndoe@example.com", "name": "John Doe" } }, "relationships": { ... } } }' ``` -------------------------------- ### Order Created Payload Example Source: https://docs.lemonsqueezy.com/help/webhooks/example-payloads This is an example of the payload received when an order is created. It includes detailed information about the order, customer, and associated products. ```json { "meta": { "event_name": "order_created" }, "data": { "type": "orders", "id": "1", "attributes": { "store_id": 1, "customer_id": 1, "identifier": "89b36d62-4f5c-4353-853f-0c769d0535c8", "order_number": 1, "user_name": "John Doe", "user_email": "johndoe@example.com", "currency": "EUR", "currency_rate": "1.08405", "subtotal": 1499.985, "discount_total": 0, "tax": 359.775, "total": 1859.76, "subtotal_usd": 1626, "discount_total_usd": 0, "tax_usd": 390, "total_usd": 2016, "tax_name": "ALV", "tax_rate": "24.00", "status": "paid", "status_formatted": "Paid", "refunded": null, "refunded_at": null, "subtotal_formatted": "€14.99", "discount_total_formatted": "€0.00", "tax_formatted": "€3.59", "total_formatted": "€18.59", "first_order_item": { "order_id": 1, "product_id": 1, "variant_id": 1, "product_name": "Product One", "variant_name": "Default", "price": 1500, "created_at": "2023-01-17T12:26:23.000000Z", "updated_at": "2023-01-17T12:26:23.000000Z", "test_mode": false }, "urls": { "receipt": "https://app.lemonsqueezy.com/my-orders/89b36d62-4f5c-4353-853f-0c769d0535c8?signature=8847fff02e1bfb0c7c43ff1cdf1b1657a8eed2029413692663b86859208c9f42" }, "created_at": "2023-01-17T12:26:23.000000Z", "updated_at": "2023-01-17T12:26:23.000000Z", "test_mode": false }, "relationships": { "store": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/store", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/store" } }, "customer": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/customer", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/customer" } }, "order-items": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/order-items", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/order-items" } }, "subscriptions": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/subscriptions", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/subscriptions" } }, "license-keys": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/license-keys", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/license-keys" } }, "discount-redemptions": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/discount-redemptions", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/discount-redemptions" } } }, "links": { "self": "https://api.lemonsqueezy.com/v1/orders/1" } } } ``` -------------------------------- ### Example API Response for Stores Source: https://docs.lemonsqueezy.com/api/getting-started/responses This example demonstrates a typical successful response when fetching a list of stores. It adheres to the JSON:API structure, including meta information, links, and the data payload containing resource objects. ```APIDOC ## GET /v1/stores ### Description Retrieves a list of stores associated with the authenticated API key. The response follows the JSON:API specification, providing metadata, links for pagination, and a data array of store resource objects. ### Method GET ### Endpoint /v1/stores ### Parameters #### Query Parameters - **page[number]** (integer) - Optional - The page number to retrieve. - **page[size]** (integer) - Optional - The number of results per page. - **sort** (string) - Optional - The field to sort the results by. ### Request Example ```curl https://api.lemonsqueezy.com/v1/stores \ -H 'Accept: application/vnd.api+json' \ -H 'Content-Type: application/vnd.api+json' \ -H 'Authorization: Bearer {api_key}' ``` ### Response #### Success Response (200) - **meta** (object) - Contains pagination information such as `currentPage`, `lastPage`, `perPage`, and `total`. - **jsonapi** (object) - Specifies the JSON:API version, typically "1.0". - **links** (object) - Contains URLs for navigating through paginated results, including `first` and `last` page links. - **data** (array) - An array of resource objects, where each object represents a store. - **type** (string) - The type of the resource, e.g., "stores". - **id** (string) - The unique identifier for the store. - **attributes** (object) - Contains the store's data, including `name`, `slug`, `domain`, `plan`, `currency`, sales figures, and timestamps. - **relationships** (object) - Links to related resources like products, orders, and subscriptions. - **links** (object) - A link to the specific store resource. #### Response Example ```json { "meta": { "page": { "currentPage": 1, "from": 1, "lastPage": 1, "perPage": 10, "to": 10, "total": 10 } }, "jsonapi": { "version": "1.0" }, "links": { "first": "https://api.lemonsqueezy.com/v1/stores?page%5Bnumber%5D=1&page%5Bsize%5D=10&sort=name", "last": "https://api.lemonsqueezy.com/v1/stores?page%5Bnumber%5D=1&page%5Bsize%5D=10&sort=name" }, "data": [ { "type": "stores", "id": "1", "attributes": { "name": "My Store", "slug": "my-store", "domain": "my-store.lemonsqueezy.com", "url": "https://my-store.lemonsqueezy.com", "avatar_url": "https://app.lemonsqueezy.com/storage/avatars/stores/1/czTkMkDm4Vfb8PZehb5c29XFCm9JZyJx0AjEZP7s.png", "plan": "fresh", "country": "US", "country_nicename": "United States", "currency": "USD", "total_sales": 1, "total_revenue": 999, "thirty_day_sales": 0, "thirty_day_revenue": 0, "created_at": "2024-05-24T14:15:06.000000Z", "updated_at": "2024-06-15T10:03:14.000000Z" }, "relationships": { "products": { "links": { "related": "https://api.lemonsqueezy.com/v1/stores/1/products", "self": "https://api.lemonsqueezy.com/v1/stores/1/relationships/products" } }, "orders": { "links": { "related": "https://api.lemonsqueezy.com/v1/stores/1/orders", "self": "https://api.lemonsqueezy.com/v1/stores/1/relationships/orders" } }, "subscriptions": { "links": { "related": "https://api.lemonsqueezy.com/v1/stores/1/subscriptions", "self": "https://api.lemonsqueezy.com/v1/stores/1/relationships/subscriptions" } }, "discounts": { "links": { "related": "https://api.lemonsqueezy.com/v1/stores/1/discounts", "self": "https://api.lemonsqueezy.com/v1/stores/1/relationships/discounts" } }, "license-keys": { "links": { "related": "https://api.lemonsqueezy.com/v1/stores/1/license-keys", "self": "https://api.lemonsqueezy.com/v1/stores/1/relationships/license-keys" } }, "webhooks": { "links": { "related": "https://api.lemonsqueezy.com/v1/stores/1/webhooks", "self": "https://api.lemonsqueezy.com/v1/stores/1/relationships/webhooks" } } }, "links": { "self": "https://api.lemonsqueezy.com/v1/stores/1" } } ] } ``` ``` -------------------------------- ### Setup LemonSqueezy SDK Source: https://docs.lemonsqueezy.com/guides/tutorials/in-app-purchases Initialize the LemonSqueezy SDK in your Express application using your API key from environment variables. ```javascript lemonSqueezySetup({ apiKey: process.env.LEMONSQUEEZY_API_KEY }); ``` -------------------------------- ### Install Lemon Squeezy JS SDK Source: https://docs.lemonsqueezy.com/guides/tutorials/nextjs-saas-billing Install the official Lemon Squeezy JavaScript SDK using PNPM. This SDK provides comprehensive access to the Lemon Squeezy API. ```bash pnpm install @lemonsqueezy/lemonsqueezy.js ``` -------------------------------- ### Authenticated Request Example Source: https://docs.lemonsqueezy.com/api/getting-started/requests This example demonstrates how to make an authenticated GET request to the /v1/users/me endpoint using cURL. ```APIDOC ## GET /v1/users/me ### Description Retrieves information about the authenticated user. ### Method GET ### Endpoint https://api.lemonsqueezy.com/v1/users/me ### Headers - **Accept**: application/vnd.api+json - **Content-Type**: application/vnd.api+json - **Authorization**: Bearer {api_key} ### Request Example ```bash curl "https://api.lemonsqueezy.com/v1/users/me" \ -H 'Accept: application/vnd.api+json' \ -H 'Content-Type: application/vnd.api+json' \ -H 'Authorization: Bearer {api_key}' ``` ### Response #### Success Response (200) - **data** (object) - Contains the user object. - **type** (string) - The resource type. - **id** (string) - The user's unique identifier. - **attributes** (object) - User attributes. - **email** (string) - The user's email address. - **name** (string) - The user's name. - **created_at** (string) - The timestamp when the user was created. - **updated_at** (string) - The timestamp when the user was last updated. #### Response Example ```json { "data": { "type": "users", "id": "1", "attributes": { "email": "test@example.com", "name": "Test User", "created_at": "2020-10-10T10:00:00.000Z", "updated_at": "2020-10-10T10:00:00.000Z" } } } ``` ``` -------------------------------- ### LemonSqueezy.Setup(options) Source: https://docs.lemonsqueezy.com/help/lemonjs/methods Initializes Lemon.js on your page. It accepts an options object which can include an eventHandler callback function. ```APIDOC ## LemonSqueezy.Setup(options) ### Description Initializes Lemon.js on your page. ### Method `LemonSqueezy.Setup(options)` ### Parameters #### Request Body - **options** (object) - Required - An object containing setup options. - **eventHandler** (function) - Optional - A callback function that handles events. ```javascript eventHandler: (event) => { // Do whatever you want with this event data } ``` ``` -------------------------------- ### Authenticated API Request Example Source: https://docs.lemonsqueezy.com/api/getting-started/requests This example demonstrates how to make an authenticated GET request to the /users/me endpoint using cURL. Ensure you replace {api_key} with your actual API key. ```curl curl "https://api.lemonsqueezy.com/v1/users/me" \ -H 'Accept: application/vnd.api+json' \ -H 'Content-Type: application/vnd.api+json' \ -H 'Authorization: Bearer {api_key}' ``` -------------------------------- ### LemonSqueezy Setup with Event Handler Source: https://docs.lemonsqueezy.com/help/lemonjs/methods Initializes Lemon.js with a callback function to handle events. This is useful for reacting to actions within the Lemon Squeezy interface. ```javascript eventHandler: (event) => { // Do whatever you want with this event data } ``` -------------------------------- ### GET Subscription with Included Invoices Source: https://docs.lemonsqueezy.com/guides/tutorials/api-related-resources This example shows how to fetch a subscription along with its associated subscription invoices by using the `include` query parameter. ```http GET https://api.lemonsqueezy.com/v1/products/1?include=subscription-invoices` ``` -------------------------------- ### Subscription Item Usage Response Source: https://docs.lemonsqueezy.com/api/subscription-items/retrieve-subscription-item-current-usage This is an example of the JSON response you will receive when successfully retrieving the current usage for a subscription item. It includes the billing period start and end dates, the total quantity used, and the subscription's interval unit and quantity. ```json { "jsonapi": { "version": "1.0" }, "meta": { "period_start": "2023-08-10T13:08:16+00:00", "period_end": "2023-09-10T13:03:16+00:00", "quantity": 5, "interval_unit": "month", "interval_quantity": 1 } } ``` -------------------------------- ### Example API Request for Stores Source: https://docs.lemonsqueezy.com/api/getting-started/responses This `curl` command demonstrates how to request a list of stores from the Lemon Squeezy API, including necessary headers for authentication and content type. ```bash curl "https://api.lemonsqueezy.com/v1/stores" \ -H 'Accept: application/vnd.api+json' \ -H 'Content-Type: application/vnd.api+json' \ -H 'Authorization: Bearer {api_key}' ``` -------------------------------- ### Configure Lemon Squeezy SDK Source: https://docs.lemonsqueezy.com/guides/tutorials/nextjs-saas-billing Sets up the Lemon Squeezy JavaScript SDK by ensuring required environment variables (API key, store ID, webhook secret) are present and then initializing the SDK. Throws an error if any variables are missing. ```typescript // src/config/lemonsqueezy.ts /** * Ensures that required environment variables are set and sets up the Lemon * Squeezy JS SDK. Throws an error if any environment variables are missing or * if there's an error setting up the SDK. */ export function configureLemonSqueezy() { const requiredVars = [ 'LEMONSQUEEZY_API_KEY', 'LEMONSQUEEZY_STORE_ID', 'LEMONSQUEEZY_WEBHOOK_SECRET', ] const missingVars = requiredVars.filter((varName) => !process.env[varName]) if (missingVars.length > 0) { throw new Error( `Missing required LEMONSQUEEZY env variables: ${missingVars.join( ', ' )}. Please, set them in your .env file.` ) } lemonSqueezySetup({ apiKey: process.env.LEMONSQUEEZY_API_KEY }) } ``` -------------------------------- ### Create a Checkout Source: https://docs.lemonsqueezy.com/api/checkouts/create-checkout Use this endpoint to create a new checkout. You can specify custom pricing, product options, checkout options, and checkout data like discount codes or custom fields. The `preview` option can be set to true for testing. ```bash curl -X "POST" "https://api.lemonsqueezy.com/v1/checkouts" \ -H 'Accept: application/vnd.api+json' \ -H 'Content-Type: application/vnd.api+json' \ -H 'Authorization: Bearer {api_key}' \ -d $'{ "data": { "type": "checkouts", "attributes": { "custom_price": 50000, "product_options": { "enabled_variants": [1] }, "checkout_options": { "button_color": "#7047EB" }, "checkout_data": { "discount_code": "10PERCENTOFF", "custom": { "user_id": 123 } }, "expires_at": "2022-10-30T15:20:06Z", "preview": true }, "relationships": { "store": { "data": { "type": "stores", "id": "1" } }, "variant": { "data": { "type": "variants", "id": "1" } } } } }' ``` -------------------------------- ### Example API Response Structure Source: https://docs.lemonsqueezy.com/guides/developer-guide/getting-started This is an example of a JSON:API compliant response for an order. It includes data, links, and relationships. ```json { "jsonapi": { "version": "1.0" }, "links": { "self": "https://api.lemonsqueezy.com/v1/orders/1" }, "data": { "type": "orders", "id": "1", "attributes": { "store_id": 1, "customer_id": 1, "identifier": "104e18a2-d755-4d4b-80c4-a6c1dcbe1c10", "order_number": 1, "user_name": "John Doe", "user_email": "johndoe@example.com", "currency": "USD", "currency_rate": "1.0000", "subtotal": 999, "discount_total": 0, "tax": 200, "total": 1199, "subtotal_usd": 999, "discount_total_usd": 0, "tax_usd": 200, "total_usd": 1199, "tax_name": "VAT", "tax_rate": "20.00", "status": "paid", "status_formatted": "Paid", "refunded": false, "refunded_at": null, "subtotal_formatted": "$9.99", "discount_total_formatted": "$0.00", "tax_formatted": "$2.00", "total_formatted": "$11.99", "first_order_item": { "id": 1, "order_id": 1, "product_id": 1, "variant_id": 1, "product_name": "Lemonade - 2 years", "variant_name": "Default", "price": 1199, "created_at": "2021-08-17T09:45:53.000000Z", "updated_at": "2021-08-17T09:45:53.000000Z", "deleted_at": null, "test_mode": false }, "urls": { "receipt": "https://app.lemonsqueezy.com/my-orders/104e18a2-d755-4d4b-80c4-a6c1dcbe1c10?signature=8847fff02e1bfb0c7c43ff1cdf1b1657a8eed2029413692663b86859208c9f42" }, "created_at": "2021-08-17T09:45:53.000000Z", "updated_at": "2021-08-17T09:45:53.000000Z" }, "relationships": { "store": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/store", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/store" } }, "customer": { "links": { "related": "https://api.lemonsqueezy.com/v1/subscriptions/1/customer", "self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/customer" } }, "order-items": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/order-items", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/order-items" } }, "subscriptions": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/subscriptions", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/subscriptions" } }, "license-keys": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/license-keys", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/license-keys" } }, "discount-redemptions": { "links": { "related": "https://api.lemonsqueezy.com/v1/orders/1/discount-redemptions", "self": "https://api.lemonsqueezy.com/v1/orders/1/relationships/discount-redemptions" } } }, "links": { "self": "https://api.lemonsqueezy.com/v1/orders/1" } } } ``` -------------------------------- ### Lemon.js Setup Source: https://docs.lemonsqueezy.com/help/lemonjs/using-with-frameworks-libraries Initialises Lemon.js on your page. It accepts an options object with an eventHandler function that is called when Lemon.js emits an event. ```APIDOC ## Setup ### Description Initialises Lemon.js on your page. Accepts an options object with an `eventHandler` function that will be called when Lemon.js emits an event. ### Method `window.LemonSqueezy.Setup` ### Parameters #### Request Body - **options** (object) - Required - An object with a single property: - **eventHandler** (function) - Required - A function that will be called when Lemon.js emits an event. The function receives an event object with an `event` property (string). ### Request Example ```javascript window.LemonSqueezy.Setup({ eventHandler: (event) => { console.log(event.event); } }); ``` ### Response This method does not return a value. ``` -------------------------------- ### Example URL with Multiple Link Variables Source: https://docs.lemonsqueezy.com/help/products/button-link-variables Demonstrates how to include multiple order data variables as query parameters in a redirect URL. These placeholders are automatically replaced with actual order details upon purchase. ```text https://example.com/welcome?order_id=[order_id]&email=[email]&total=[total] ``` -------------------------------- ### Example License Key Validation Response Source: https://docs.lemonsqueezy.com/guides/tutorials/license-keys This is an example of a successful response when validating a license key. The 'valid' field indicates the key's status. ```json { "valid": true, "error": null, "license_key": { "id": 1, "status": "active", "key": "38b1460a-5104-4067-a91d-77b872934d51", "activation_limit": 1, "activation_usage": 5, "created_at": "2023-03-25 11:10:18", "expires_at": "2024-03-25 11:10:18" }, "instance": null, "meta": { "store_id": 1, "order_id": 2, "order_item_id": 3, "product_id": 4, "product_name": "Example Product", "variant_id": 5, "variant_name": "Default", "customer_id": 6, "customer_name": "John Doe", "customer_email": "johndoe@example.com" } } ``` -------------------------------- ### Subscription Object Response Example Source: https://docs.lemonsqueezy.com/guides/tutorials/api-related-resources An example of the JSON response when querying a subscription, including the `data` object for the subscription and `included` objects for related subscription invoices. ```json { "meta": { "page": { "currentPage": 1, "from": 1, "lastPage": 1, "perPage": 10, "to": 9, "total": 9 } }, "jsonapi": { "version": "1.0" }, "links": { "first": "https://api.lemonsqueezy.com/v1/subscriptions?include=subscription-invoices&page%5Bnumber%5D=1&page%5Bsize%5D=10&sort=-createdAt", "last": "https://api.lemonsqueezy.com/v1/subscriptions?include=subscription-invoices&page%5Bnumber%5D=1&page%5Bsize%5D=10&sort=-createdAt" }, "data": { "type": "subscriptions", "id": "1", "attributes": { "store_id": 1, "customer_id": 1, "order_id": 1, "order_item_id": 1, "product_id": 1, "variant_id": 1, "product_name": "Example Product", "variant_name": "Example Variant", "user_name": "John Doe", "user_email": "johndoe@example.com", "status": "active", "status_formatted": "Active", "card_brand": "visa", "card_last_four": "42424", "pause": null, "cancelled": false, "trial_ends_at": null, "billing_anchor": 12, "first_subscription_item": { "id": 1, "subscription_id": 1, "price_id": 1, "quantity": 5, "created_at": "2021-08-11T13:47:28.000000Z", "updated_at": "2021-08-11T13:47:28.000000Z" }, "urls": { "update_payment_method": "https://my-store.lemonsqueezy.com/subscription/1/payment-details?expires=1666869343&signature=9985e3bf9007840aeb3951412be475abc17439c449c1af3e56e08e45e1345413", "customer_portal": "https://my-store.lemonsqueezy.com/billing?expires=1666869343&signature=82ae290ceac8edd4190c82825dd73a8743346d894a8ddbc4898b97eb96d105a5" }, "renews_at": "2022-11-12T00:00:00.000000Z", "ends_at": null, "created_at": "2021-08-11T13:47:27.000000Z", "updated_at": "2021-08-11T13:54:19.000000Z", "test_mode": false }, "relationships": { "store": { "links": { "related": "https://api.lemonsqueezy.com/v1/subscriptions/1/store", "self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/store" } }, "customer": { "links": { "related": "https://api.lemonsqueezy.com/v1/subscriptions/1/customer", "self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/customer" } }, "order": { "links": { "related": "https://api.lemonsqueezy.com/v1/subscriptions/1/order", "self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/order" } }, "order-item": { "links": { "related": "https://api.lemonsqueezy.com/v1/subscriptions/1/order-item", "self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/order-item" } }, "product": { "links": { "related": "https://api.lemonsqueezy.com/v1/subscriptions/1/product", "self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/product" } }, "variant": { "links": { "related": "https://api.lemonsqueezy.com/v1/subscriptions/1/variant", "self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/variant" } }, "subscription-items": { "links": { "related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-items", "self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-items" } }, "subscription-invoices": { "links": { "related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-invoices", "self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-invoices" }, "data": [ { "type": "subscription-invoices", "id": "1" }, {"...": "..."}, {"...": "..."} ] } }, "links": { "self": "https://api.lemonsqueezy.com/v1/subscriptions/1" } }, "included": [ { "type": "subscription-invoices", "id": "1", "attributes": { "store_id": 1, "subscription_id": 1, "customer_id": 1, "user_name": "John Doe", "user_email": "johndoe@example.com", "billing_reason": "initial", "card_brand": "visa", "card_last_four": "4242", "currency": "USD", "currency_rate": "1.00000000", "status": "paid", "status_formatted": "Paid", "refunded": false, "refunded_at": null, "subtotal": 999 } } ] } ``` -------------------------------- ### Activate a License Key Source: https://docs.lemonsqueezy.com/guides/tutorials/license-keys Use this cURL command to activate a license key via the Lemon Squeezy API. Replace placeholders with actual values. Ensure the instance_name is provided. ```bash curl -X POST https://api.lemonsqueezy.com/v1/licenses/activate \ -H "Accept: application/json" \ -d "license_key=38b1460a-5104-4067-a91d-77b872934d51" \ -d "instance_name=Test" ``` -------------------------------- ### List License Key Instances by License Key ID Source: https://docs.lemonsqueezy.com/api/license-key-instances/list-all-license-key-instances This example demonstrates how to filter the list of license key instances to retrieve only those associated with a specific license key ID. The filter parameter is appended to the URL. ```curl curl "https://api.lemonsqueezy.com/v1/license-key-instances?filter[license_key_id]=1" -H 'Accept: application/vnd.api+json' -H 'Content-Type: application/vnd.api+json' -H 'Authorization: Bearer {api_key}' ``` -------------------------------- ### License Key Instance Response Object Source: https://docs.lemonsqueezy.com/api/license-key-instances/retrieve-license-key-instance This is an example of the JSON response when successfully retrieving a license key instance. It includes details about the instance, its associated license key, and timestamps. ```json { "jsonapi": { "version": "1.0" }, "links": { "self": "https://api.lemonsqueezy.com/v1/license-key-instances/1" }, "data": { "type": "license-key-instances", "id": "1", "attributes": { "license_key_id": 1, "identifier": "f70a79fa-6054-433e-9c1b-6075344292e4", "name": "example.com", "created_at": "2022-11-14T11:45:39.000000Z", "updated_at": "2022-11-14T11:45:39.000000Z" }, "relationships": { "license-key": { "links": { "related": "https://api.lemonsqueezy.com/v1/license-key-instances/1/license-key", "self": "https://api.lemonsqueezy.com/v1/license-key-instances/1/relationships/license-key" } } }, "links": { "self": "https://api.lemonsqueezy.com/v1/license-key-instances/1" } } } ``` -------------------------------- ### Update Subscription Example Source: https://docs.lemonsqueezy.com/api/subscriptions/update-subscription This cURL example demonstrates how to update a subscription by changing its variant, billing anchor, and trial end date. Ensure you replace {api_key} with your actual API key. ```curl curl -X "PATCH" "https://api.lemonsqueezy.com/v1/subscriptions/1" \ -H 'Accept: application/vnd.api+json' \ -H 'Content-Type: application/vnd.api+json' \ -H 'Authorization: Bearer {api_key}' \ -d $'{ "data": { "type": "subscriptions", "id": "1", "attributes": { "variant_id": 11, "billing_anchor": 29, "trial_ends_at": "2024-04-20T10:30:00Z" } } }' ```