Development discussions around Shopify APIs
Hello guys,
I am having problems with applying discount codes that I've previously created using API call.
To be more specific - there is a delay time between creating discount code via API call and discount becoming available for use.
First, I create price rule using API endpoint:
POST /admin/api/#{api_version}/price_rules.json
Then I create discount from that same price rule using endpoint:
POST /admin/api/#{api_version}/price_rules/#{price_rule_id}/discount_codes.json
and then I return that discount code back to frontend, but I can't use the code for first couple of seconds or minutes.
When I look in "Discounts" section in admin panel, I can see that new discount is there, but under discount status it says "scheduled" instead of "active". It becomes active after some time. Sometimes it becomes active immediately, sometimes after few seconds, and sometimes after minute or two.
Once it becomes active I can use it normally and it works fine, but I don't know why am I getting that unknown delay?
When I'm creating price rule, I'm setting "starts_at" property to current datetime value, so I don't think that should be a problem?
My question is:
Where does that delay come from, and how to prevent that?
Thank you!
Solved! Go to the solution
This is an accepted solution.
Hello @Josh
Yeah, I thought so and that makes sense. Although, that delay varies. Sometimes it takes only 1 second, and sometimes it takes much longer (don't know how much longer, but usually it is inside of 10-15 seconds timeframe like you said). One time I needed to wait for approx 1 min, but I wasn't able to reproduce that more than once.
I think it would be good idea to have some kind of workaround for that in case shop owner wants to create discount code on the fly and apply that discount to customer's checkout right away.
Also, I think it would be useful to include "discount_status" object property in discounts API call responses, so we can check discount status periodically.
Interesting thing is that I haven't experienced that discount activation delay when I created discount code manually in shopify discounts section. Discount gets created and activated right away.
Anyway, we found a workaround. We are now pre-creating price rules and discounts, and when we have to use them, we just update price_rule's value and apply the discount code. Looks like we solved the delay issue with it. It does the job, but it would be definitely nice to have simpler and cleaner solution in the future.
Hello @jldevelop ,
I think a minor delay between creating a discount code and it being usable in the checkout is fairly reasonable, things will take some time to propagate/process in order for the checkout to be aware that the discount code has been activated and available for use.
With that being said though, do you have any kind of rough estimate of how often you find it taking minutes before the discount will work? I have only been able to replicate it taking ~10-15 seconds at best, which I don't think would be avoidable.
I would recommend trying to take the current time when creating your price rules and discount codes and then subtracting a minute or two to see if that helps with this issue at all, and let me know if you find that makes a difference.
Josh | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
This is an accepted solution.
Hello @Josh
Yeah, I thought so and that makes sense. Although, that delay varies. Sometimes it takes only 1 second, and sometimes it takes much longer (don't know how much longer, but usually it is inside of 10-15 seconds timeframe like you said). One time I needed to wait for approx 1 min, but I wasn't able to reproduce that more than once.
I think it would be good idea to have some kind of workaround for that in case shop owner wants to create discount code on the fly and apply that discount to customer's checkout right away.
Also, I think it would be useful to include "discount_status" object property in discounts API call responses, so we can check discount status periodically.
Interesting thing is that I haven't experienced that discount activation delay when I created discount code manually in shopify discounts section. Discount gets created and activated right away.
Anyway, we found a workaround. We are now pre-creating price rules and discounts, and when we have to use them, we just update price_rule's value and apply the discount code. Looks like we solved the delay issue with it. It does the job, but it would be definitely nice to have simpler and cleaner solution in the future.
Is there still no proper solution for this, we're also experiencing this issue now.
I am also experiencing this issue now, but only on some accounts across our store.
Also experiencing this, regularly waiting multiple minutes for the price rules and discount codes to propagate
User | RANK |
---|---|
8 | |
7 | |
3 | |
3 | |
3 |
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By