Discount code pushing from my app

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

Hi Fulltoss,

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:

  1. First, you need to create a script tag in your Shopify app, which will be executed in the storefront.

  2. In this script tag, you can create a logic to detect if the customer has $100 in the wallet.

  3. 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.

  4. 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:

mutation discountCodeBasicCreate($basicCodeDiscount: DiscountCodeBasicInput!) {
  discountCodeBasicCreate(basicCodeDiscount: $basicCodeDiscount) {
    codeDiscountNode {
      # DiscountCodeNode fields
    }
    userErrors {
      field
      message
    }
  }
}

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.

Hope this helps!