Graphql Admin orderCreate discount issues

Hi there,

As many of us I am migrating from the Rest API to Graphql Admin. I have two questions:

  1. When does the Rest API become fully unavailable?
  2. I am struggling with the discount part on orderCreate. In our use case we can’t use the checkout sheet, so we have our own custom checkout page. The flow is as follows:
  • User uses the Cart API to add products, add discount, manage their address etc.
  • User clicks on pay
  • Cart Object is sent to my rails backend
  • Cart Object is used to create the Order object for the orderCreate API

This all works, and I am able to create the order. However, it seems like automated discounts or discount codes are not being applied. Which is super frustrating.

This my gql request:

mutation OrderCreate($order: OrderCreateOrderInput!, $options: OrderCreateOptionsInput) {
  orderCreate(order: $order, options: $options) {
    userErrors {
      field
      message
    }
    order {
      id
      discountApplications(first:10) {
      nodes {
        value {
          ... on MoneyV2 {
          currencyCode
          amount
          }
          ... on PricingPercentageValue {
          percentage
          }
        }
        ... on DiscountCodeApplication {
          code
        }
      }
    }
      currentSubtotalPriceSet {
        presentmentMoney {
          amount
          currencyCode
        }
        shopMoney{
          amount
          currencyCode
        }
      }
      totalTaxSet {
        shopMoney {
          amount
          currencyCode
        }
      }
      totalPriceSet {
        shopMoney {
          amount
          currencyCode
        }
      }
      currentTotalPriceSet {
        shopMoney {
          amount
          currencyCode
        }
      }
      lineItems(first: 5) {
        nodes {
          variant {
            id
          }
          id
          title
          quantity
          taxLines {
            title
            rate
            priceSet {
              shopMoney {
                amount
                currencyCode
              }
            }
          }
        }
      }
    }
  }
}

Input:

{
  "options": {
    "inventoryBehaviour": "DECREMENT_OBEYING_POLICY"
  },
  "order": {
    "email":"test@test.com",
    "currency": "CNY",
    "lineItems": [
      {
        "variantId": "gid://shopify/ProductVariant/46004283965731",
        "quantity": 1
      }
    ],
    "discountCode": {
      "itemFixedDiscountCode": {
        "code": "product1234p"
      }
    },
    "shippingAddress": {
      "address1": "123 Test Street",
      "address2": null,
      "zip": "200040",
      "city": "Shanghai",
      "countryCode": "CN",
      "provinceCode": "SH",
      "phone": null,
      "lastName": "Smith",
      "firstName": "Mary"
    },
    "billingAddress": {
      "address1": "123 Test Street",
      "address2": null,
      "zip": "M5T1G4",
      "city": "Shanghai",
      "countryCode": "CN",
      "provinceCode": "SH",
      "phone": null,
      "lastName": "Smith",
      "firstName": "Mary"
    },
    "note": "Waiting for pickup"
  }
}

So basically my question comes down to, how does the automatic discount get applied and how do coupon codes apply?

In the REST API it was super easy, in GQL it sucks.

Hi Ashkan,

When you say:

we have our own custom checkout page

is that a totally different checkout than the regular Shopify checkout page? Automatic discounts are not directly applied through the orderCreate mutation. Instead, they are automatically applied at checkout if the conditions of the discount rules are met. If you are creating orders programmatically, automatic discounts will not be applied unless you replicate the logic of those discounts in your custom implementation.

Discount codes can be applied during the orderCreate mutation by specifying the discountCode field in the input.

Hi Liam!

Thank you for the quick reply. It’s a totally different check out. We are using the Shopify API in the context of a WeChat Mini Program. Our global users visit the shopify website, while our users in China use the mini program to do the check out. I can’t use the regular checkout page here, since all the domains involved in the checkout process don’t have a Chinese ICP license.

The problem I am encountering now is that the automatic discounts are being applied in the Storefront CART Api.

But I can’t turn that cart directly into an order, so in a bit of a workaround I am recreating the cart in the orderCreate mutation.

But all good, I understand that the automatic discounts are not not possible with the orderCreate mutation. I’ll try to find a work around.

As for the discount codes, I was able to get it to work. But I have to also add the amountSet (Which should be optional based on the documentation):

    {
      "code": get_discount_code,
      "amountSet": {
        "shopMoney": {
          "currencyCode": "CNY",
          "amount": calculate_total_discount
        }
      }
    }

Hi @Liam-Shopify,

I am facing an issue here as well. We have itemPercentageDiscountCode from our vendors but we are not storing the percentage discount that is associated with that code. With the GraphQL OrderCreate endpoint are we required to send in the percentage as well as it is not a required argument but for some reason if we don’t pass it the discount does not appear.

Shouldn’t it automatically apply the percentage that was allocated by the vendor for us.

{ itemPercentageDiscountCode: { code: discount_code } }

or does it have to be

variables[:order][:discountCode] = { itemPercentageDiscountCode: { code: discount_code, percentage: x } }