Providing Store Credit through Shopify Flow App on Order Paid Trigger

I’ve found a perfect usecase for the Shopify Flow App but I don’t think it’s possible to use it in this way. Can someone prove me wrong?

The idea is to create a Loyalty Programme using the Shopify Flow App and the new Shopify Store Credit functionality. So when an Order is Paid I want to trigger a Flow that calculates the 1% value of the Order value and then add that amount to the Customers Store Credit value.

Sounds like a reasonable usecase and great way to utilize the Shopify Flow App. Is this currently possible?

FYI, I’m not interested in Apps that provide this functionality, I want to know if it’s possible using Shopify Flow App and if so, how.

1 Like

Hi MsMinis, this should be possible by using the Order paid trigger, then a Run code action that calculates the credit based on the order value, then a Send Admin API request that updates the storeCreditAccountCredit. However, that mutation may not be available until the 2024/07 API is released so you may have to wait on that or implement as a refund or other endpoint available in the 2024/01 API.

1 Like

That’s great to hear. I’ve set up the Flow as you’ve explained currently and it seems to work great beside the endpoint that is not yet available. I assumed because of the name it would have already been available but it’s not. Is there an ETA for that version to be released?

You could also just use send http request action meanwhile.

Hi,
Did you find a solution to this? Does it work with Flow?

I wanted to chime in on this thread with an update. The info posted was super helpful but at the time, wasn’t 100% doable in Shopify Flow since the Admin API version running in flow was not the latest and did not include storeCreditAccountCredit. I can confirm that the latest version does now include this as well as other mutations that weren’t available before. So it is now possible to this entirely within Flow using the included Admin API Request option. I just completed a fairly robust rewards flow that we had previously been doing with Growave. Doing it in Flow works way better, is more flexible, and in my experience, way more stable than using Growave which is pretty regularly breaking down and requiring support to step in.

So glad Shopify finally updated this. It will really open up a lot of possibilities.

1 Like

Good to hear, I have mine working in Pipedream already so not mega keen to rebuild it but if it ever breaks I might give the Flow version a shot. If you want to share I’d love to see it.

I’m using a Run Code action to calculate the credit to be applied. My application also applies a different percentage of the order to be credited based on what tier the customer is (3% - default, 4.5%, or 6% based on certain customer tags if present):

Input:

query {
  order {
    customer {
      tags
    }
    subtotalPriceSet {
      shopMoney {
        amount
      }
    }
  }
}

Output:

"Output object"
type Output {
  "Calculated Store Credit"
  storeCredit: Float!
}

Code:

/**
 * Calculate the store credit to be applied on purcahse
*/
export default function main({order}) {
  const subtotal = order.subtotalPriceSet.shopMoney.amount;
  var reward = 0.03;
  if(order.customer.tags.includes('elite-member')){
    reward = 0.045;
  } else if(order.customer.tags.includes('vip-member')){
    reward = 0.06;
  }
  return { storeCredit: (subtotal * reward).toFixed(2)};
}

Then I use the Send API request to send the storeCreditAccountCredit mutation to the GraphQL Admin API:

{
  "id": "{{order.customer.id}}",
  "creditInput": {
    "creditAmount": {
      "amount": "{{runCode.storeCredit}}",
      "currencyCode": "{{order.currentTotalPriceSet.presentmentMoney.currencyCode}}"
    },
    "expiresAt": "{{order.createdAt | date: "%s" | plus: 31536000 | date: "%Y-%m-%dT%H:%M:%S%z"}}"
  }
}

The real thing that took a some trial and error was, from that I could see, the expiresAt field appears to be required. I tried excluding it and setting that to false since I wanted my credits to not have an expiry date but none of those options seemed to work. So instead, I’m using a date that is 365 days after the order creation which should work. If anyone can suggest why I wasn’t able to create a credit without an expiry date, I’d welcome the input.

I’m still testing things to make sure all my conditions work as expected but so far, things appear to be working well.

I just tried this in my shop, and it’s great!

We do want to set an expiration date, but I’m not sure how to set up a flow to let people know that they have credit expiring. Do you know how I could go about setting up that flow?

There’s an email template for expiring store credit.

I searched but I didn’t see one. Are you referring to the expiring gift card template?

Apologies, its a segment template not an email template:

FROM customers
SHOW customer_name, note, subscription_status, location, orders, amount_spent
WHERE store_credit_accounts MATCHES (
next_expiry_date BETWEEN today AND +7d
)
ORDER BY updated_at

I found that when I went digging around after my last reply, but when I tried to create the segment by applying some credit to a test account to expire in 6 days the information didn’t populate. I’m not sure where I’m going wrong.

I don’t know if this is by design or not, but I realized earlier today that this code issues credit of X% on the order subtotal without taking the credit being applied into consideration so customers are getting credits on the carts full price, not the discounted price.

It’s a great idea, but Shopify Flow alone can’t natively issue or adjust store credit. You’ll need a third-party app for that.

We use an app called Koin and have our flow set up this way. Hope that helps!

You can use Flow’s Send Admin API request to issue credit. Using an app’s action is also OK of course.

1 Like

Alternatively, if you don’t mind using third-party apps, you can use the Execute GraphQL request action from the Flow Companion app to run any GraphQL queries.
The advantage of this approach is that this action automatically handles cases where the GraphQL API has too many requests - it retries the request in such situations.
It also automatically detects errors in the userErrors field of the query and terminates the workflow with a description of the error.

If you’re looking for an app to handle this, the Credita app could be the perfect fit. It allows you to set flexible rules for granting Shopify’s native store credit - such as rewarding new account sign-ups, high-value orders, or shipped orders - without any coding. All granted credits are recorded in a clear activity log, so you can easily track and review your store credit history. You can install the app and test it further.

If you need any additional help beyond this, feel free to ask.

Hi everyone!

This is absolutely possible now!

When this was originally asked, it wasn’t technically feasible, but Shopify has made some major updates that make this exact use case work perfectly.

What Changed?

Shopify Flow now uses the 2025-01 version of the GraphQL Admin API, which includes the store credit mutations that weren’t available in earlier versions. This functionality is now accessible through Flow’s “Send Admin API request” action.

How to Set It Up

Here’s exactly how you can create that 1% order value loyalty program:

Trigger: Order paid
Action: Send Admin API request using the storeCreditAccountCredit mutation

The API call you’ll use:

mutation storeCreditAccountCredit($id: ID!, $creditInput: StoreCreditAccountCreditInput!) {
  storeCreditAccountCredit(id: $id, creditInput: $creditInput) {
    storeCreditAccountTransaction {
      amount { amount currencyCode }
      account { id balance { amount currencyCode } }
    }
    userErrors { message field }
  }
}

Variables:

{
  "id": "gid://shopify/Customer/[CUSTOMER_ID_FROM_FLOW]",
  "creditInput": {
    "creditAmount": {
      "amount": "[CALCULATED_1%_OF_ORDER_TOTAL]",
      "currencyCode": "[ORDER_CURRENCY]"
    }
  }
}

You’ll use Flow’s built-in variables to calculate 1% of the order total and pass the customer ID automatically.

The API automatically creates a store credit account if one doesn’t exist, and customers can see their balance and use it at checkout when logged in. Plus, customers typically spend more than their store credit balance, increasing your average order value.

This is exactly the kind of creative use case that makes Flow so powerful - you’re building a custom loyalty program using native Shopify functionality without any third-party apps!

Hope this helps anyone looking to implement something similar. Feel free to ask if you need clarification on any of the technical details.

Cheers!
Shubham | Untechnickle


P.S. - For anyone wondering about the technical requirements, you’ll need the Store Credit functionality enabled in your Shopify admin, which is available for most current plans.