Retreive Company object custom metafield using graphql

Topic summary

A developer is implementing a credit limit feature for a B2B Shopify store using GraphQL in a custom cart and checkout validation app.

Initial Problem:

  • Encountered errors when trying to retrieve Company object custom metafields
  • GraphQL validation failed with “Cannot query field ‘company’ on type ‘Input’”
  • Images show schema.graphql file modifications

Solution Provided:
The correct GraphQL query path is through buyerIdentity.purchasingCompany.company.metafield, not directly accessing company on the Input type. A working query example was shared retrieving the “credit_remaining_limit” metafield from the “b2b” namespace.

Evolving Requirements:
The developer wants to:

  • Block customers at checkout (not cart) when credit limit is insufficient
  • Allow orders only if customers select “net payment” option
  • Permit credit card payments when credit limit is exceeded
  • Hide the “choose payment later” option based on order total using Payment Customization API
  • Accept split payments (credit limit + credit card)

Current Status:
Split payment functionality is not currently supported. The discussion remains open regarding how to properly target and hide specific payment methods like “Net-7, Net-15, choose payment later” using payment customization.

Summarized with AI on November 7. AI used: claude-sonnet-4-5-20250929.

Hi

I am trying to retreive Company object custom metafield using graphql on custom apps(cart and checkout validation based) for implementing credit limit feature in the B2B store.

I updated Input to Company in the schema.graphl file Below I added all the files

I get this error when I try to deploy the app:

Command failed with exit code 1: npm exec – graphql-code-generator --config package.json
[FAILED] GraphQL Document Validation failed with 1 errors;
[FAILED] Error 0: Cannot query field “company” on type “Input”.
[FAILED] at C:/Users/xyz/shopify-functions/lucrative-consumer-app/extensions/cart-checkout-validatio
n/src/run.graphql:14:3

Kindly let me know how this can be resolved.

Thanks

Khasim

Hi there

The company inside in the buyerIdentity -purchasingCompany-company

so you should rewrite your input to as below.

{
  cart: {
    buyerIdentity: {
      customer{
        numberOfOrders
    }
      purchasingCompany{
         company{
             metafield{
                key(xxx)
                namespace
             }
         }
    }
  }
  cost{

  }
}

FYI I ran this query to get the metafield value of Company object

query RunInput {
cart {
buyerIdentity {
purchasingCompany {
company {
testValue: metafield(namespace: “b2b”, key: “credit_limit_remaining”) {value}
}
}
}
cost {
subtotalAmount {
amount
}
}

}
}

Hi @Eric-HAN

Can you let me know if the validation can be done on checkout page instead of cart page(https://shopify.dev/docs/api/functions/reference/cart-checkout-validation/graphql) . At present I am blocking the customer on the cart page if their credit limit is less than order total, I want them to proceed to checkout but block them only if they select net payment option in the checkout. And allow them to place order if they select credit card payment option.

Thanks

Khasim

H i,there

i suggest you use Payment Customization API (https://shopify.dev/docs/api/functions/reference/payment-customization)) to do this feature . when your customer credit limit is less than order total, you could limit their payment options or hide some of them . otherwise show the available options.

Hi @Eric-HAN

Is it possible to accept split payments, such as deducting from the available credit limit and charging the remaining amount from a credit card?

sorry

The current stage might not be supported.
If you discover appropriate solutions, please share them to me . Thanks

1 Like

Can you please help on how we can target “choose payment later” option using the payment customization, in the hide function I tried to add using these “Choose payment later”, “Net-7”, Net-15" but still payment method shows on the checkout. I wanted to hide choose payment method later based on some order total and show only credit card option