logo
  • Product
  • Solutions
  • Developers
  • Resources
  • Pricing
  • Log in
  • Create a store
  • Product

  • Pricing
  • Try for free
  • Log In
  • Merchandising

  • Operations

  • Building

  • Integrations

  • Products

    Powerful modeling and versatile presentation of your entire catalog.

  • Subscriptions

    Sell recurring physical and virtual products alongside one-time offerings.

  • Discounts

    Get the sale with coupons, BXGY promotions, and automatic discounts.

  • Wholesale

    Sell B2B like it's DTC, along with volume pricing, customer groups, and invoicing.

  • Content

    Manage all your products content through the admin dashboard.

  • Users

    Multi-store admin accounts and role-based permission controls.

  • Customers

    Manage customer info, generate reports, and see buyer activity.

  • Orders

    Edit orders anytime and get the right information for smooth fulfillment.

  • Fulfillment

    Ship from multiple locations, track inventory, and split shipments.

  • Reporting

    Monitor your store's performance to ensure you have visibility across the business.

  • Storefronts

    Swell storefronts are fully customizable, allowing you to create just the right experience.

  • Checkouts

    Use our hosted checkout, integrate with a partner, or build a custom flow.

  • Payments

    Connect multiple gateways simultaneously, store cards, and split payments.

  • Internationalization

    Go global with region-specific languages, pricing, and payment methods.

No-code integrations

Connect with 40+ services for marketing, payments, fulfillment, automation, and more.

See all integrations →

Use Cases

  • Direct-to-consumer

    Tell your story and give customers a unique shopping experience

  • Subscriptions

    Sell personalized subscription bundles, memberships, and one-time items together

  • B2B/B2C

    Support retail and wholesale customers from one catalog and dashboard

  • Marketplaces

    Create a B2B or B2C marketplace with multi-vendor carts and split payouts

Customer Stories

  • Spinn Coffee

    A coffee revolution sparked by a connected machine and marketplace

  • Smashing magazine

    Global tax and shipping for complex product bundles

  • Infinitas Learning

    Delievering leading educational experiences in Europe

All customer stories →

Documentation

  • Quickstart

  • Backend API reference

  • Frontend API reference

  • Guides

  • Core concepts

  • Storefronts

Community

  • GitHub

  • Discussion forum

  • Changelog

  • API status

Resources

  • Help Center

    The latest industry news, updates and info.

  • Customer stories

    Learn how our customers are making big changes.

  • Become a partner

    For agencies creating innovative commerce experiences.

Latest blog posts

  • Nov 06, 2025

    Build smarter workflows with App Functions

  • Oct 22, 2025

    Storefronts V2 and the future of Swell Apps

  • Changelog

  • API Status

  • Contact us

Blog

Build smarter workflows with App Functions

Swell App Functions offer new opportunities to customize the platform for unique use cases. In this article, we’ll take a deeper look at how functions work to build custom workflows in Swell.

November 05, 2025

A recent introduction to Swell is our Apps framework, which brings many new opportunities to customize the platform for unique use cases. Among the capabilities that an app can provide is hosted functions.

How functions unlock new opportunities

Functions are written in JavaScript or TypeScript and deployed to Swell’s cloud environment, powered by Cloudflare Workers. They can be triggered by data events (similar to webhooks), by a schedule, or invoked directly by HTTP. When called, a function is wrapped in the context of a Swell store and its API in order to provide a seamless development experience without unnecessary boilerplate.

Here’s an example of a function that sends a text message confirmation when an order is shipped.

// functions/shipment-text-notification.ts
export const config: SwellConfig = {
  description: 'Send SMS confirmation on order shipment',
  model: {
    events: ['shipment.created'],
    conditions: {
      tracking_url: { $exists: true }
    }
  }
};

export default async function (req: SwellRequest) {
  const { swell, data, store } = req;
  
  const order = data; // The updated order record

  const settings = await swell.settings(); // App settings
  
  const { twilio_account_id, twilio_auth_token, twilio_from_number } = settings;

  // Use an external SMS service like Twilio via fetch
  await fetch(`https://api.twilio.com/2010-04-01/Accounts/${twilio_account_id}/Messages.json`, {
    method: 'POST',
    headers: {
      'Authorization': 'Basic ' + btoa(`${twilio_account_id}:${twilio_auth_token}`),
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: new URLSearchParams({
      To: order.billing.phone,
      From: twilio_from_number,
      Body: `Your order ${order.number} has shipped! Track it at ${order.tracking_url}`
    })
  });
}

In this example, we see how a function can be used asynchronously, but there are many use cases that require a function to intercept an event and affect the outcome synchronously.

Here’s an example of a function that is invoked in the middle of a request, and modifies the data of an order before it is submitted.

// functions/high-value-order.ts
export const config: SwellConfig = {
  description: 'Apply custom discount to high-value orders',
  model: {
    events: ['before:order.submitted']
  }
};

export default function (req: SwellRequest) {
  const { data } = req;
  
  const order = data; // Incoming order data

  // Add custom validation or modification
  if (order.sub_total > 1000) {
    order.discounts = orders.discounts || [];
    order.discounts.push({
      id: 'high-value-discount',
      amount: 50
    });
  }

  // Return modified data to continue the creation process
  return order;
}

Test and deploy

Development and deployment are made easy with the Swell CLI. A single command will compile and run local versions of your functions using Cloudflare Wrangler behind the scenes.

$ swell app dev

✔ App function server running on port 3001

Functions:
  shipment-text-notification
    Trigger: Model
    Events: shipment.created
    Description: Send SMS confirmation on order shipment
  high-value-order
    Trigger: Model
    Events: before:order.submitted
    Description: Apply custom discount to high-value orders

→ Call functions at: http://localhost:3001/<function-name>

The swell app dev command will cause Swell to proxy all backend events to your local machine so that you can test and visualize behavior before pushing to the cloud. You can also invoke the functions directly using an API tool such as Postman with a call to the URL listed by the command.

As you make changes, functions are automatically recompiled and reloaded on the fly, as well as deployment to Swell as a part of your development app version.

You'll see the output of any console logs emitted when running swell app dev, and while functions are executed in the cloud, you can see their input and output in the Swell dashboard under Developer -> Console -> Logs.

Context is key

Functions are isolated by the Cloudflare Worker platform, and their logic contains only what is necessary to get the job done. To simplify and reduce boilerplate as much as possible, Swell compiles and wraps function code in a context that provides easy access to the store’s API and app settings, along with detailed information about the event or trigger. This context is what makes the development experience feel magical.

Diving deeper, the context object—passed as req to your function—includes everything you need at your fingertips. There's swell, our SDK for API interactions like querying products or updating records. The data object holds the event-specific payload, such as the record being created or updated, and the store object gives access to store-wide details and settings. No more wrestling with authentication or setup—it's all prepped and ready, letting you focus on the logic that drives value.

Function logs

Event, schedule, and request triggers

Functions can be triggered by three main action types.

Event Functions react to platform changes, like record creations or updates in models such as products or orders. Events can be either asynchronous, like webhooks, or synchronous using before or after hooks. Use conditions to filter invocations and sequence numbers to prioritize execution in chains—ensuring your function runs exactly when and where it should.

Scheduled Functions automate tasks over time. Tie them to a model's date field for dynamic timing, like capturing payments on a set schedule, or use cron expressions for recurring jobs, such as daily inventory syncs. This opens doors to proactive ecommerce automation without constant oversight.

Request Functions turn your app into a custom API engine. Exposed as HTTP endpoints, they handle regular HTTP methods, with options for caching, public access, or secure key-based auth. Ideal for building custom logic into headless storefronts or integrating third-party services on-demand.

Each trigger type leverages the same edge-powered runtime for zero cold starts and optimal performance, making Swell Apps a scalable extension of your store.

Getting started

Start by installing the Swell CLI and running swell create function to scaffold your first one. Develop locally with swell app dev for real-time testing via a secure tunnel. Deploy effortlessly—changes push automatically to our Cloudflare-backed edge.

A few best practices: Keep code lean, using ES modules and avoiding unsupported Node APIs. Leverage conditions to minimize invocations. For request functions, enable caching on GETs to boost performance. Remember, while powerful, functions have limits on memory and execution time, so design for efficiency.

For full details, dive into our App Functions Developer Docs. We're excited to see what you build—share your creations, provide feedback, or partner with us to shape the future.

Next-level commerce for everyone.

X.comGitHubLinkedIn

Subscribe to our newsletter for product updates and stories

Subscribe

Resources

Help CenterDeveloper CenterCommunityAgenciesChangelog

Use cases

SubscriptionsB2B WholesaleMarketplaceOmnichannelDirect-to-consumer

Explore

FeaturesPricingIntegrationsCustomer stories

Developers

OverviewDocumentationGuidesStorefrontsHeadlessSwell Apps

Company

BlogAbout usPartners

© 2025 Swell. All rights reserved.

Privacy PolicyTerms of Service