discountAutomaticAppCreate creates discount but metafields still set "null"

discountAutomaticAppCreate creates discount but metafields still set "null"

gjohnstonTT
Shopify Partner
5 1 5

Hi y'all hope you're doing well. Currently working on a Shopify Function that will discount a product based on if a certain tag if it exists, however I'm running into a strange issue when creating and updating my function. Currently when I create my discount and enter all the input variables as expected along with my custom metafield the discount exists, but metafield value is set to null. However if I find the id of the discount and then use the discountautomaticupdate mutation and pass in the metafield input variables the value is updated and works as expected, however if I go to update the metafield values again without passing through an Id nothing changes, but if I pass through the metafeild Id to be updated the changes are reflected if I re-query the discount but not within the function itself as it still defaults to the values initially created. Any insight into whether the issue is from my mutations or approach would be greatly appreciated. I've included context below of the mutations and their respective input variables and my run.graphql file. Thank you in advance! 

 

Context: 

Create

mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {
  discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {
    automaticAppDiscount {
      discountId

    }
    userErrors {
      field
      message
    }
  }
}
Input Variables 
{
  "automaticAppDiscount": {
    "combinesWith": {
      "orderDiscounts": true,
      "productDiscounts": true,
      "shippingDiscounts": true
    },
    "functionId": "17eb3b10-d454-4638-9e75-29f3b97b0062",
    "metafields": [
      {
        
        "key": "function-configuration",
        "namespace": "tag-discount",
        "type": "json",
        "value": "{\"tags\": [\"testing\"], \"percentage\": 25.0}"
      }
    ],
    "startsAt": "2023-12-04T00:00:00Z",
    "title": "25% Off"
  }
}

Update

mutation {
  discountAutomaticAppUpdate(
    id: "gid://shopify/DiscountAutomaticNode/1431592927528",
    automaticAppDiscount: {
      metafields: [
        {
          id:"gid://shopify/Metafield/30617205408040"
          key: "function-configuration"
          value: "{ \"tags\": [\"testing\"], \"percentage\": 25.0 }"
          type: "json"
        }
      ]
    }
) {
    userErrors {
      field
      message
    }
  }
}

run.graphql

query RunInput($tags: [String!]){
  cart{
    lines{
      merchandise{
      __typename
      ... on ProductVariant{
        id
        product{
          hasAnyTag(tags: $tags)
          hasTags(tags: $tags){
            tag
            hasTag

          }
        }
      }
      }
    }
  }
   discountNode {
    metafield(namespace: "tag-discount", key: "function-configuration"){
      value
    }
  }
  
}
Replies 0 (0)