totalTaxAmount missing in cart object

Jujuba
Shopify Partner
23 0 6

Hi, 

 

I´m creating carts by using the API. Following is the mutation:

 

 

mutation {
	cartCreate(input: {lines: {merchandiseId: "gid://shopify/ProductVariant/44134907969855", quantity: 1}, buyerIdentity: {countryCode: DE, deliveryAddressPreferences: {deliveryAddress: {firstName: "Max", lastName: "Mustermann", country: "Germany", city: "Hildesheim", zip: "63522", address1: "Straße 1"}}}}) {
		userErrors {
			message
		  }
		  cart {
			checkoutUrl
			id
			cost {
			totalTaxAmount {
				amount
			}
			  totalAmount {
				amount
			  }
			  subtotalAmount {
				amount
			  }
			}
			lines(first: 1) {
			  edges {
				node {
				  quantity
				  id
				  sellingPlanAllocation {
					priceAdjustments {
					  price {
						amount
					  }
					}
				  }
				  merchandise {
					... on ProductVariant {
					  image {
						url
					  }
					  title
					  id
					  price {
						amount
					  }
					  sellingPlanAllocations(first: 1) {
						edges {
						  node {
							priceAdjustments {
							  price {
								amount
							  }
							}
						  }
						}
					  }
					}
				  }
				}
			  }
			}
		  }
		}
	  }

 

 

 

 

Unfortunately, taxAmount is always null and subtotalAmount is same as totalAmount. 

I use a real address and have set up tax override for Germany in my store.

I also have checked "charge tax" for the products.

 

Can anybody help? I need to know the taxAmount to build a proper B2B Shop.

Thanks,

Ju 

Replies 7 (7)

Liam
Shopify Staff
2731 298 769

Hi Jujuba,

From looking at this mutation, it does seem like you have the correct setup for charging taxes in your store and for your products. But, if you're not seeing tax amounts when creating carts through the API, here are a few things you could check:

 

  • Tax Settings: Verify that your store's tax settings are properly configured for Germany. You mention that you have set up tax overrides one thing to check would be to make sure that these overrides apply to the products you're adding to the cart.
  • Address Format: Check that the address format is correct and recognizable by Shopify. If Shopify can't interpret the address, it may not be able to calculate taxes correctly.
  • Cart and Checkout Settings: Depending on the Shopify plan, certain features around taxes might not be available at the cart level but may be present at checkout.

Take a look at the settings above and see if any of them might be impacting taxAmount and subtotalAmount - if you're still seeing issue, let us know here.

 

Hope this helps,

Liam | Developer Advocate @ 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 Shopify.dev or the Shopify Web Design and Development Blog

Jujuba
Shopify Partner
23 0 6

Hi Liam, 

thanks for the response! 

I checked the three bulletpoints.

  • tax overrides apply. I checked by visiting the webUrl of checkout. Taxes are applied on checkout page
  • I used my own and other valid addresses, so that should be okay
  • I couldn't find any restrictions on cart api depending on the shopify plan. I use a development store

Do I need to use locale-aware URL´s when calling the cart endpoint?

 

Thanks

 

BR Julien

 

Liam
Shopify Staff
2731 298 769

Hi again Jujuba,

 

Locale-aware URLs are generally used for non-checkout things like storefront translations and different currency formats and I don't think they directly affect tax calculation. 

 

Looking into this a bit more, the cart API would typically not be used to calculate taxes in real-time. That calculation generally happens at checkout when the customer's information is complete and the system has all the data required to determine the appropriate tax rate. Are the native settings for taxes that you'd create in the store admin not enough for your use case?

Liam | Developer Advocate @ 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 Shopify.dev or the Shopify Web Design and Development Blog

Jujuba
Shopify Partner
23 0 6

Which API ist used to calculate taxes in real-time?

My client is operating a headless store and wants to have a b2b section.

Therefore, the price of products inside the cart needs to be without tax. When the customer goes to the checkout the tax has to be displayed (this is already done by Shopify).

Liam
Shopify Staff
2731 298 769

Hi again Jujuba,

 

For real-time tax calculation, Shopify itself doesn't provide an API. Instead, third-party services like Avalara, TaxJar, or Vertex are often used. These services provide APIs that you can call to calculate taxes based on a variety of factors, like the type of product, shipping address, and more.

 

In a headless Shopify setup, you might be pulling product and pricing information via the Storefront API, then adding items to the cart and transitioning to checkout using Shopify's Checkout API or your custom solution. For tax calculations in this scenario, you'd need to integrate with a third-party tax service API.

 

To display prices without taxes on your store and then add them at checkout, you can set your prices to be tax-exempt at the product level, then calculate and add tax during the checkout process.

 

Hope this helps!

Liam | Developer Advocate @ 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 Shopify.dev or the Shopify Web Design and Development Blog

Jujuba
Shopify Partner
23 0 6

Thanks. 

In that case I don't understand the documentation about the Cart API. What is the purpose of the totalTaxAmount if its always null? 

When can I use it and when does it work? 

There must be an option to get back tax from the API, its a mandatory feature.

Hellojere
Shopify Partner
3 0 0

I'm right there with you. The documentation for the Cart API has been a consistent source of confusion for me too. Why even have a totalTaxAmount if it's perpetually null? It's borderline misleading.

 

It's a no-brainer that retrieving tax information should be straightforward. This isn't some advanced, niche feature—it's basic e-commerce functionality.

 

And honestly, it feels like par for the course with Shopify's APIs. Every time I dive in, it's like navigating a minefield of ambiguities and inconsistencies. They really need to get their act together.