Automating Minimum Quantity Requirement for Shopify Discount Codes Created via Klaviyo

Automating Minimum Quantity Requirement for Shopify Discount Codes Created via Klaviyo

keyurdodiya
Tourist
19 0 2

I use Shopify and have set up Klaviyo to automatically generate bulk discount codes with the name "BUY2SAVE10." Each customer receives a unique code via email. However, due to a technical limitation in Klaviyo, the generated codes do not include a minimum purchase requirement of 2 items. Since Klaviyo cannot set this automatically, I have to manually update each discount code multiple times a day to ensure the minimum quantity requirement is applied.

Is there a way to automate this process so that whenever a "BUY2SAVE10" discount code is created, it automatically updates from "No minimum requirements" to requiring a minimum of 2 items?

Reply 1 (1)

Small_Task_Help
Shopify Partner
991 39 93

Hi,

Hope this will help

Creating a helper program (a script) that automatically updates your discount codes in Shopify to include minimum quantity requirement whenever they are created

Code example (use Python or Node.js to interact with Shopify API)

import requests

shopify_url = "https://your-store-name.myshopify.com/admin/api/2023-04/discount_codes.json"
api_key = "your-api-key"
password = "your-password"

# Get existing discount codes from Shopify
response = requests.get(shopify_url, auth=(api_key, password))

if response.status_code == 200:
    discount_codes = response.json()['discount_codes']
    for code in discount_codes:
        if code['code'] == "BUY2SAVE10" and code.get('minimum_quantity', 0) == 0:
            # Update the discount code with a minimum quantity of 2
            update_url = f"https://your-store-name.myshopify.com/admin/api/2023-04/discount_codes/{code['id']}.json"
            payload = {
                "discount_code": {
                    "minimum_quantity": 2
                }
            }
            update_response = requests.put(update_url, json=payload, auth=(api_key, password))

            if update_response.status_code == 200:
                print(f"Discount code {code['code']} updated with minimum quantity of 2 items.")
            else:
                print(f"Failed to update discount code {code['code']}.")
else:
    print("Failed to retrieve discount codes.")

 

To Get Shopify Experts Help, Click Here or E-mail - hi@ecommercesmalltask.com
About Us - We are Shopify Expert India
At Google My Business - Ecommerce Small Task - Hire Shopify Developers Ahmedabad