Re: GraphQL mutation discountAutomaticAppCreate fails

GraphQL mutation discountAutomaticAppCreate fails

nbfusion
Shopify Partner
3 0 3

In my examples below I will replace my actual function id with "FUNCTIONID". Just know that yes I used the correct id.

I can issue this query in GraphQL (using version 2023-04 since you can't query for functions in earlier versions):

 

query
{
	shopifyFunction(id:"FUNCTIONID"){
    apiType
    apiVersion
    title
    description
    inputQuery
    app {
      id
    }
  }
}

The query succeeds and it finds my function:

{
  "data": {
    "shopifyFunction": {
      "apiType": "product_discounts",
      "apiVersion": "2023-01",
      "title": "volume-discounts",
      "description": "",
      "inputQuery": "query Input {\n  cart {\n    lines {\n      quantity\n\t  cost{\n\t\tamountPerQuantity{\n\t\t\tamount\n\t\t}\n\t  }\n      merchandise {\n        __typename\n        ...on ProductVariant {\n            id\n\t\t\tproduct{\n\t\t\t\tid\n\t\t\t\tmetafield(namespace: \"nfusionsolutions\", key: \"pricetiers\"){\n\t\t\t\t\tvalue          \n\t\t\t\t}\n\t\t\t}\t\t\t\t\n        }\n      }\n    }\n  }\n}\n",
      "app": {
        "id": "gid://shopify/App/4345823"
      }
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 2,
      "actualQueryCost": 2,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 967,
        "restoreRate": 50
      }
    }
  }
}

 

So I know this function exists. However, if I try a mutation it fails:

mutation {
  discountAutomaticAppCreate(automaticAppDiscount: {
    title: "Volume discount",
    functionId: "FUNCTIONID",
    startsAt: "2022-06-22T00:00:00"
  }) {
     automaticAppDiscount {
      discountId
     }
     userErrors {
      field
      message
     }
  }
}

 

Here is the error response:

{
  "data": {
    "discountAutomaticAppCreate": {
      "automaticAppDiscount": null,
      "userErrors": [
        {
          "field": [
            "automaticAppDiscount",
            "functionId"
          ],
          "message": "Function not found."
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 973,
        "restoreRate": 50
      }
    }
  }
}

 

I have tried this in 2 development stores. One with "Checkout Extensibility" developer preview and one without. It fails in both.

The function I am trying to mutate is an extension that I have added using Shopify CLI and based on examples here (https://shopify.dev/docs/apps/discounts/experience/getting-started) and here (https://shopify.dev/docs/apps/selling-strategies/discounts/experience/config). It builds and deploys successfully to an existing public plugin that has been live in the Shopify store for some time (https://apps.shopify.com/precious-metal-product-prices). I can see the extension deployed in the partner developer dashboard under the details for that app. And as previously stated when that app is deployed to my test store I can query for that function in GraphQL. However, without the mutation my code is never called. What is the problem here and how can it be addressed?

Replies 3 (3)

Olingyn
Shopify Partner
5 0 3

Were you able to fix your issue? I'm exactly in the same case 😞

Olingyn
Shopify Partner
5 0 3

Seems that it has been fixed by reinstalling Shopify GraphQL app!

StudioForty9
Shopify Partner
5 0 3

Another possible issue is not adding the read_discounts and write_discounts scope in shopify.app.toml

For Delivery and Payment customisations updating the scopes isn't necessary but it is for Discounts. My function wouldn't install until I reinstalled the app with these scopes. The "Function not found" error is obviously not very useful in this scenario.