How to Run a workflow if the Value user entered exist within the database?

You have to run a simple search on your table of coupons. The search constraints would be ‘Code = Inputted text’ & ‘Active is empty’. If the search:count > 0, then the inputted coupon exists and you can apply the discount + set Active to ‘no’ (or even better ‘current data time’ so you know when it was used). If the search returns nothing, then the coupon entered is not valid.

There is a consideration which is way too often overlooked; the coupon datatype has to be private, and it cannot be searched for. Otherwise a tech-savvy (not particularly savvy) user would just be able to query the coupon codes from your servers and use them freely.

Set your coupon codes to completely private and unsearchable. Then create a backend workflow, check the checbox that says ‘this workflow ignores privacy rules’ + run the search in there and use the workflow block ‘Return data from APi’ and just return a 1 if the search was succesful, and a 0 if it wasnt.
Then connect the API Worfklow to your API connector.
I explain how to set this API call up in the API connector in the following post: How to trigger a backend workflow? - #3 by nico.dicagno

Once set up, just call the API worklow from the page, and if it returns a 1, apply the coupon. If it returns a 2 do not.
Two options for returning further data about the coupon (discount percentage, fixed discount/ applicable shops / minimum spend to apply).

  1. Return the Unique ID of the coupon + on privacy rules, set all fields you need to visible.
    This might not be well known but Searching a Thing by Unique ID will return the Thing desipite privacy rules not being met
    This can be used to your advantage. If you return the Unique id, you can fetch all the fields which are visible by default by everyone else.
    Not an amazing solution, because you have to run another search after API response.

  2. Return all the Coupon data you need from the API response directly, and use custom states to save the data to the page. This is probably the better solution.