Add company 'ordersCount' to Discount Function API / Cart Validation API Inputs

The input object to ‘cart.lines.discounts.generate.run' provides cart.buyerIdentity.purchasingCompany.company, but the company object doesn’t have the Admin API property ‘ordersCount’. Only cart.buyerIdentity.purchasingCompany.companyLocation has it. It’d be useful to have the company wide order count.

Our use case is for a first order discount - it should only apply on the very first order placed by a company, irrespective of which location.

Hey @Paul_Holmes You’re right that ordersCount is only available on the location object in the Discount Function API input and not on company. I can confirm the Admin API does have ordersCount on the Company object, so the data exists, it’s just not exposed in the Functions schema today.

As a potential workaround in the meantime, you could read a company-level metafield in your function’s input query since company.metafield is available in the Discount Function schema. I would just set up a has_ordered metafield on the company resource that you could update whenever you see it updated at the company object-level via an admin API webhook listener on your end, and then check that metafield value in your discount function to decide whether to apply the first-order discount.

More on how to access metafields in function input queries here: Build a discounts UI with admin UI extensions and company metafields via the Admin API here: company - GraphQL Admin

I realize that’s extra infrastructure for something that feels like it should just be a field on the company object in the Functions input though, so I’m happy to log this as a feature request.

Just to make sure I capture the full picture, is the first-order discount the primary use case here, or are there other scenarios where you’d want access to the company-wide order count in a function? Curious if this is something you’d also want available in the Cart Validation API or if the discount function is the main one.

Let me know if I can clarify anything on our end here!

Hey @Alan_G ,

Thanks for the speedy reply! Yes, we’re going to use a metafield to store this for now, but it’s another bit of redundant infra. that we’d prefer to avoid. On other use cases: absolutely, we’re having the same problem on the Cart Validation API with creating a custom MOV function. In that case, we’re using the same metafield as for the discount function.

1 Like

Thanks @Paul_Holmes - just following up on this here to confirm I’ve passed your feature feedback on, let me know if I can help with anything else!