I am building a shopify app and i want to make a feature where if customer has 100$ in the wallet, he can select 50% can push for a “create a discount code” request and then 50% discount code will be generated
Can you help me how to push for a discount code generation request when my app will be under a script tag in the website
Creating a discount code request can be done [using the discountCodeBasicCreate mutation](http://using%20the discountCodeBasicCreate mutation) that’s part of the GraphQL Admin API. Here is a general flow of how you can achieve this:
First, you need to create a script tag in your Shopify app, which will be executed in the storefront.
In this script tag, you can create a logic to detect if the customer has $100 in the wallet.
If the condition is met, you can send a request to your app’s server-side endpoint (using AJAX or Fetch API), and pass necessary data (like customer id or discount amount) to this endpoint.
Then in your app’s server-side, you need to handle this request. Here you can call Shopify’s GraphQL Admin API to create a new discount code.
Here is an example of how you create a discount code using GraphQL Admin API:
After the discount code is created, you can send it back to the client-side and show it to the customer. Please note that you need to have a necessary access scope (write_discounts) to create discount codes.