Shopify Flow B2B Fix: Capitalizing on 'PurchasingCompany' for Flawless Order Automation
Hey store owners and fellow Shopify enthusiasts! It's your friendly Shopify migration expert here, diving into a really interesting — and frankly, a bit tricky — challenge that popped up in the community recently. We're talking about Shopify Flow, specifically when you're trying to automate tasks for your B2B orders. Flow is an absolute powerhouse for streamlining operations, but sometimes, it throws a curveball. This particular discussion highlighted a common gotcha when trying to access company details, and it's a fantastic example of why our community is so invaluable!
The Head-Scratcher: Accessing B2B Company Location ID in Shopify Flow
The thread started with alexandre-1tcc, who was building a Shopify Flow to trigger when a new B2B order was created. Their goal was pretty standard for B2B operations: send an HTTP request to an external system, and crucially, include the purchasing company's location ID in the payload. They were doing everything right, or so it seemed.
Using the variable picker in Shopify Flow, they could drill down to order.purchasingEntity.purchasingCompany.location.id. The picker even showed it as a valid option! But here's where the frustration kicked in: when they tried to use this variable in an HTTP request body or even a simple "Create a variable" step, they got an error: "purchasingCompany" is invalid. Replace this variable. Talk about confusing, right? The tool shows it, but then rejects it.
The "Aha!" Moment: It's All About Capitalization
Thankfully, the community quickly jumped in with the fix. v.marychenka pinpointed the issue directly: the variable picker was offering purchasingCompany with a lowercase 'p', but Shopify Flow's backend actually expects PurchasingCompany with a capital 'P'. It's one of those subtle differences that can drive you absolutely batty!
The solution is surprisingly simple, yet easily overlooked: you need to manually type the variable with the correct capitalization. So, instead of letting the picker insert the lowercase version, you'd modify it to look like this:
"location_id": "{{order.purchasingEntity.PurchasingCompany.location.id}}"
As Ecom_swift_LLC confirmed, this capitalization discrepancy is the core problem. A little detail, but a huge roadblock if you don't know about it!
Beyond the Fix: Building Robust B2B Flows with purchasingEntity
While the capitalization fix solves the immediate error, Ecom_swift_LLC added another crucial piece of advice for building truly robust Flows. They pointed out that purchasingEntity is a "union type." What does that mean for you?
It means that purchasingEntity can represent either a Customer (for your regular D2C orders) or a PurchasingCompany (for your B2B orders). If your Flow fires on an order placed by a regular customer (who isn't associated with a company), the PurchasingCompany field simply won't exist. If your Flow then tries to access something like order.purchasingEntity.PurchasingCompany.location.id, it will error out because that path doesn't exist for a customer order.
To prevent this, it's safest to add a condition to your Flow that first checks the type of purchasingEntity. This way, your Flow degrades gracefully for non-B2B orders instead of breaking completely.
Putting It All Together: Step-by-Step for Your Shopify Flow
Let's combine these insights into an actionable plan for your Shopify Flow:
- Start Your Flow: Begin with your trigger, for example, "Order created."
- Add a Condition: Immediately after your trigger, add a "Condition" block. This is where you'll check if the order is actually a B2B company order.
- Check the
purchasingEntityType: In your condition, you'll want to check iforder.purchasingEntityis of the typePurchasingCompany. Shopify Flow typically allows you to select this as a condition like:Order > Purchasing entity > Type > Is equal to > Purchasing company. - (If True Path) Access Company Data: In the "YES" branch of your condition (meaning it IS a B2B company order), proceed with your action (e.g., "Send HTTP request," "Create a variable," etc.).
- Manually Type the Variable: When you're inserting the variable for the company's location ID, make sure you manually type
PurchasingCompanywith the capital 'P'. So, your variable will look like this:{{order.purchasingEntity.PurchasingCompany.location.id}} - (If False Path) Handle Non-B2B Orders: In the "NO" branch of your condition (for regular customer orders), you can either do nothing, send a different notification, or route the order to a different process. This ensures your Flow doesn't break for every non-B2B order.
Why This Matters for Your B2B Operations
This little capitalization quirk and the union type consideration might seem minor, but they're critical for building robust and reliable B2B automation. A well-configured Shopify Flow can save you countless hours, reduce manual errors, and keep your external systems perfectly in sync with your Shopify store. It's these kinds of expert insights from the community that help us all build better, more resilient solutions. If you're looking to scale your wholesale operations, a solid Shopify B2B setup with smart Flow automation is absolutely essential. Always remember to test your Flows thoroughly, especially after making changes, and don't hesitate to lean on the amazing Shopify community when you hit a wall. Happy automating!
