How to read metafield id after creating DiscountAutomaticApp?

markus12
Shopify Partner
30 1 14

Hi,

 

Creating a DiscountAutomaticApp accepts metafields 

https://shopify.dev/api/admin-graphql/2023-01/input-objects/DiscountAutomaticAppInput

 

but no metafield is included in response

https://shopify.dev/api/admin-graphql/2023-01/objects/DiscountAutomaticApp

 

This should allow a metafield query, similar to Product.

 

Also, how can one read discounts after creating? App discounts aren't included in 

https://shopify.dev/api/admin-graphql/2023-01/queries/automaticDiscountNodes

 

Thanks.

Replies 4 (4)

Nick_Wesselman
Shopify Staff
156 39 60

The structure of the discount types is a bit more complex than products, you sometimes need to use fragments to "cast" to the right type.

Metafields are available on the `DiscountNode` type. You can get app discounts via the `discountNodes` query.

  discountNodes(first: 50) {
    nodes {
      discount {
        ... on DiscountAutomaticApp {
          appDiscountType {
            functionId
          }
        }
      }
      metafields(first: 1) {
				nodes {
          key
        }
      }
    }
  }


Not sure it's possible to obtain during creation though. Can I ask why you need the metafield ID when creating the discount?

Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

markus12
Shopify Partner
30 1 14

Thanks, that does list the id indeed.

 

why you need the metafield ID when creating the discount?

 

To be able to modify metafield value later.

Tried using https://shopify.dev/api/admin-graphql/2022-07/mutations/discountAutomaticAppUpdate

but metafield.id "is required when you update a metafield."

 

markus12
Shopify Partner
30 1 14

PS: Speaking of metafields, could we please have private metafields too? Functions also belong to an app, so they would have no issue reading them.

ronnylc
Shopify Partner
2 0 1

private metafields is deprecated instead you can use namespace feature $app:my-name