How to use shopify function to apply discount code in cart

I use discountCodeAppCreate to generate a discount code, when the customer adjusts the number of products in the cart (say the number of products in the cart > 2) I want to apply the discount code to that product automatically.

I know I can use discountAutomaticAppCreate to create a discount that automatically applies when the condition is met, but discountAutomaticAppCreate is limited to only 5 active discountAutomaticAppCreates

But how to apply discount code in cart, because I don’t find any place to enter discount code while in cart

I found solution

using Storefront API to create a cart, attach your discount code when creating a cart to attribute

"discountCodes": [
"

This discount code will trigger shopify function when the quantity of items in the cart changes