- I just given "from date" only for the price rule.
- In the cart price rules form page, we can see that either Stop Rules Processing or Discard Subsequent Rules.
- Just set "Yes" for Stop Rules Processing/Discard Subsequent Rules.
- Some existing coupon may affect your current coupon.I removed that coupon.
- Make sure in the manage coupon codes tab, confirm either coupon is used or unused.
I've created the auto generated coupon using the below api.
$accessToken = 'ymuo1rkbggrh467tmtlk502hw9fd2v8z'
$response = Http::withHeaders([
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $accessToken,
])->post(
'https://example.com/rest/default/V1/salesRules',
[
'rule' => [
"name" => "TESTCOUPON",
"website_ids" => [1],
"customer_group_ids" => [0, 1, 2, 3],
"uses_per_customer" => 1,
"is_active" => true,
"stop_rules_processing" => true,
"is_advanced" => true,
"sort_order" => 0,
"discount_amount" => 10,
"discount_step" => 0,
"apply_to_shipping" => false,
"times_used" => 0,
"is_rss" => true,
"coupon_type" => "SPECIFIC_COUPON",
"use_auto_generation" => true, // Setting auto-generation to false
"uses_per_coupon" => 1,
"from_date" => Carbon::now()->toDateString(),
"simple_action" => "by_fixed"
]
]
);
$actionRule = $response->json();
// Make POST request to create autogenerate coupon by using rule_id
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . $accessToken,
'Content-Type' => 'application/json',
])->post('https://example.com/rest/default/V1/coupons/generate', [
'couponSpec' => [
'rule_id' => $actionRule['rule_id'],
'quantity' => 5,
'length' => 12,
]
]);
Finally, The coupon is working.Here, I attached the screenshot for your reference.