Monday, June 30, 2025

Creating Moonbase licenses from Shopify sales

Tobias Lønnerød Madsen

Moonbase Founder

Tobias is the technical founder of Moonbase, with a long history of building e-commerce for software companies.

In case you haven't yet moved to using Moonbase to power your e-commerce and payments, and still need to fulfill orders in Shopify, you can easily set up a flow to fulfill Moonbase products.

This depends on using a workflow within the Shopify Flow app, so install that if you want to follow along. To begin, create a new flow using the trigger "Fulfillment order ready to fulfill":

This will make the workflow run for each new order, at which point we can continue by iterating over all line items in that order by adding an action called "For each loop (iterate)", targeting fulfillmentOrder.lineItems:

In case you have other products in your Shopify account that may not want to be fulfilled by Moonbase, you can simply add a condition that checks the SKU on the line item:

At this point you are ready to add the HTTP request to Moonbase by adding an action called "Send HTTP request":

This request should be a POST request going to https://{your-account-id}.moonbase.sh/api/licenses/provision. The headers need to contain a api-key value, where you should add an API key made in your Moonbase Account Settings to your Shopify secrets. You also need to add a content-type of application/json to the headers. Lastly, add the body which looks at the order to create a license for the line item to the customer:

{
    "customer": {
        "name": "{{fulfillmentOrder.order.customer.displayName}}",
        "email": "{{fulfillmentOrder.order.email}}"
    },
    "requests": [
        {
            "productId": "{{lineItemsForeachitem.sku}}",
            "quantity": {{lineItemsForeachitem.totalQuantity}}
        }
    ]
}

To avoid having to manually fulfill this line item in Shopify, we add one last step to set the line item to fulfilled by using the "Send Admin API request" action:

This step should use the fulfillmentCreateV2 API, with the following input:

{
  "fulfillment": {
    "notifyCustomer": false,
    "lineItemsByFulfillmentOrder": [
      {
        "fulfillmentOrderId": "{{fulfillmentOrder.id}}",
        "fulfillmentOrderLineItems": [
          {
            "id": "{{lineItemsForeachitem.id}}",
            "quantity": {{lineItemsForeachitem.totalQuantity}}
          }
        ]
      }
    ]
  },
  "message": "Digital item to be auto-fulfilled"
}

And that's all there is to it! With this workflow active, products will now be fulfilled by Moonbase, with emails going to new customers.

Start selling through Moonbase

Sign up today to get started selling your software through Moonbase.