Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Cannot find unitPriceMeasurement field in GraphQL API

Cannot find unitPriceMeasurement field in GraphQL API

RiadhMa
Tourist
6 0 5

Hello,

I would like use the unitPriceMeasurement  field for my products, in the documentation it says that it exists under ProductVariant object but when I fetch it in Shopify GraphiQL API I cannot find it.
Someone can provide me with any information about this?

Thank you.

Replies 21 (21)

davidhoang
Shopify Partner
20 0 9

I have the same problem. The error message is "Field 'unitPriceMeasurement' doesn't exist on type 'ProductVariant'".

HunkyBill
Shopify Partner
4853 60 568

It is supposed to be only for customers in certain countries. You get that field if you are Germany for example, but not Canada. At least that is how it looked a few years ago when they introduced the unit pricing schema. Maybe it is just an oversight... I dunno. Is this released in general now?

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
davidhoang
Shopify Partner
20 0 9

I tried that on a dev store which have the country set to Germany. The unit price field then enabled on the store and I set some test values for products already. Still the API is saying that it's not available.

HunkyBill
Shopify Partner
4853 60 568

Not sure then. A Dev Store should have everything turned on. Maybe it requires an actual setting of the API itself to turn that on. Meaning you have to ask if you want it and it won't work unless you qualify.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
davidhoang
Shopify Partner
20 0 9

I tried it on a live client store which is located in Germany. The merchant has the unit prices setup and configured. Same error that I got on the dev store.

When the dev store was configured to be in a different country, the option was not available. It's only available after switching to Germany, inline with what is said here: https://help.shopify.com/en/manual/intro-to-shopify/initial-setup/sell-in-germany/price-per-unit

Who should I contact to check whether this API can be "turned on", if it needs to be?

Thanks.

mleimbach
Shopify Partner
7 0 5

Hi David,
the link you provided only talks about the integration of the unitprices in a theme that does not support them by default yet,
but not the write access to the ProductVariant fields through the api.

We are also located in Germany ourselves and face this problem every day, especially when bigger clients who want to migrate to shopify from another shop system or need to update their unitprices through an ERP-software.

It is frustrating since the api needs to exist internally (I'm pretty sure the admin-frontend also only triggers an api..) and is just not published or documented.

Calling out to the german partner manager Roman Zenner did not help yet.
The thread was discussed by a lot of people in the german partner slack channel but nothing happened.

Even noticing losing potential plus leads due to that lack of api support did not bother them.

A very sad story. 😞
we are still hoping for the best.

Matthias Leimbach
Lead Development

beeclever
Koblenz, Germany
HunkyBill
Shopify Partner
4853 60 568

It is money left on the table for sure. Not the first case, not the first time. I guess you just want to keep monitoring the API released in GQL to see when those aspects are covered.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
magnalister
Shopify Partner
10 0 10

In Germany, the unit price is mandatory information in several product categories, and sellers could be punished if they don't provide this information for their products. We as a Shopify-App should have access to this information to transfer product data to marketplaces like eBay and Amazon.
We have the same problem to access to override tax.
If Shopify doesn't want to implement these features, German sellers have to switch to another shop-systems.

Gift-o-the-Jab
Navigator
370 24 98

Hey @magnalister  @mleimbach 

This was already sent up as a feature request to the feature requests backlog. We'll see how that develops as the dev and product teams have to weigh up the PPU API factors of viability, global demand, feasibility, system stability, all moving parts, and so on and so forth...

It may be a yay or a nay. Drücke die Daumen!

chris214
Excursionist
46 0 10

Hi Matthias  & @RiadhMa & @HunkyBill @magnalister 

 

(how) did you fix or work around this issue?

 

thanks in advance

chris

HunkyBill
Shopify Partner
4853 60 568

No one has fixed this issue. Shopify has been ignoring this for 16+ years. Maybe in the next API release there will be a few bones to play with.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
letsmakeshops
Visitor
2 0 0

Hi Chris,

 

we found a solution by adding the fields of UnitPriceMeasurement as metafields to ProductVariantInput.

This maintains the structure and you can easily replace the unit_price snippets in templates with new field names like:

 

item.variant.unit_price

becomes

item.variant.metafields.unit_price_item.unit_price.value

 You simply define the metafields in your shop: https://[[YOUR_SHOP]].myshopify.com/admin/metafields/productvariant

 

Upside:

If Shopify ever decides to add the feature to the API you only search and replace your metafields.

 

Downside:

The Shopify settings for UnitPriceMeasurement are completely ignored.

 

 

HunkyBill
Shopify Partner
4853 60 568

The funny thing about this is that for all intents, I would bet the farm that Shopify internally just uses metafields for these kinds of things anyway. So no loss or gain there, just a re-invention!

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
Ryback
Shopify Partner
7 0 5

Hi!

We have the same problem and want to use the solution with the metafields.

But this doesn´t solve that on the checkout/summary page (not the basket page) the unit price will not be shown and without shopify plus it`s not possible to custom edit the summary template.

Or miss i something?

letsmakeshops
Visitor
2 0 0

No, we can't modify the order template either.

The unit price for items in the order summary is displayed only when you manually enter a unit price in on the products admin. 

Looks like Shopify either has to add unit price management to the API or allow modifing order summary prices for all humans. 

 

RBaumgartner
Shopify Partner
4 0 2

It's still the same. It is not part Admin API 2202-04 and it is not yet in 2022-07 release candidate. Especially for German shops this information is relevant! 

HotHanni
Not applicable
1 0 1

Its very interesting.

I tried to change this in the admin UI i. e. https://admin.shopify.com/store/xxx/products/yyy

Then we have this request:

 

{
  "operationName": "ProductSaveVariantsUpdate",
  "variables": {
    "productId": "gid://shopify/Product/xxxx",
    "variantsToBulkUpdate": [
      {
        "id": "gid://shopify/ProductVariant/xxxx",
        "showUnitPrice": true,
        "unitPriceMeasurement": {
          "quantityValue": 500,
          "quantityUnit": "ML",
          "referenceValue": 1,
          "referenceUnit": "L"
        }
      }
    ]
  },
  "query": "mutation ProductSaveVariantsUpdate($productId: ID!, $variantsToBulkUpdate: [ProductVariantsBulkInput!]!) {\n  productVariantsBulkUpdate(\n    productId: $productId\n    variants: $variantsToBulkUpdate\n  ) {\n    userErrors {\n      field\n      message\n      __typename\n    }\n    __typename\n  }\n}\n"
}

 

Well, yea, looks as easy as possible.
... But ...

 

Simple Node Shopify GraphQL...

 

const shopify = shopifyApi({
  apiKey,
  apiSecretKey,
  adminApiAccessToken,
  apiVersion,
  isEmbeddedApp: false,
  scopes: ['read_products', 'write_products', 'write_inventory'],
  hostName: shop,
  future: {
    lineItemBilling: true
  }
});

await this.client.request(`mutation(
  $productId: ID!,
  $input: ProductVariantsBulkInput!) {
    productVariantsBulkUpdate(productId: $productId, variants: [$input]) {
      userErrors {
        field
        message
      }
    }
  }`,
{
  variables: {
    productId: xxxx,
    inventoryItemId: yyyy,
    input: {
      showUnitPrice: true,
      unitPriceMeasurement: {
        quantityValue: 500,
        quantityUnit: "ML",
        referenceValue: 1,
        referenceUnit: "L"
      }
    }
  }
});

 

I mean it also looks very simple.

But executed it results in ...

 

{
  "errors": {
    "networkStatusCode": 200,
    "message": "GraphQL Client: An error occurred while fetching from the API. Review 'graphQLErrors' for details.",
    "graphQLErrors": [
      {
        "message": "Variable $input of type ProductVariantsBulkInput! was provided invalid value for showUnitPrice (Field is not defined on ProductVariantsBulkInput), unitPriceMeasurement (Field is not defined on ProductVariantsBulkInput)",
        "locations": [
          {
            "line": 3,
            "column": 15
          }
        ],
        "extensions": {
          "value": {
            "id": "gid://shopify/ProductVariant/xxxx",
            "sku": "xxxx",
            "price": "44.95",
            "compareAtPrice": "35.71",
            "weight": 0.17293,
            "weightUnit": "KILOGRAMS",
            "barcode": "xxxx",
            "inventoryItem": {
              "cost": 35.71,
              "requiresShipping": true,
              "tracked": true,
              "measurement": {
                "weight": {
                  "unit": "KILOGRAMS",
                  "value": 0.17293
                }
              },
              "harmonizedSystemCode": "123123"
            },
            "inventoryPolicy": "DENY",
            "showUnitPrice": true,
            "unitPriceMeasurement": {
              "quantityValue": 500,
              "quantityUnit": "ML",
              "referenceValue": 1,
              "referenceUnit": "L"
            }
          },
          "problems": [
            {
              "path": [
                "showUnitPrice"
              ],
              "explanation": "Field is not defined on ProductVariantsBulkInput"
            },
            {
              "path": [
                "unitPriceMeasurement"
              ],
              "explanation": "Field is not defined on ProductVariantsBulkInput"
            }
          ]
        }
      }
    ],
    "response": {
      "size": 0,
      "timeout": 0
    }
  }
}

 

So the only way to solve that is via browser automation. Very sad & bad but ... Shopify 😀

ShopifyDevSup
Shopify Staff
1453 238 522

Hi @HotHanni,

 

This is currently expected behaviour, as at this time product unit prices are not available to be edited or created via our API. They can however be retrieved from the API on existing orders through the `Order.lineItem.unitPrice` field.

 

They can also be edited in the Shopify Web Admin for stores located in Germany or France by default, or if your store is located elsewhere you can reach out to Shopify Support to enable the feature, though this request must come from the store's account owner.

I do understand how this is not ideal for your business operations, and I will be sending up some feedback on your behalf that you would like to see Unit Prices manageable via the API directly. We do take all our merchants and partners feedback with great value, and the more feedback we get for features like this, the more likely and quicker it will be added!

 

I hope this helps, and i hope you have a great day 🙂

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

LingerLab
Shopify Partner
1 0 0

When I discovered this feature, I activated it and redesigned the product detail template in my store. I import my products from a third-party app using a script. As I started updating it, I realized I couldn’t upload products to Shopify because the API lacks this functionality. This has been very frustrating as I invested a lot of time and effort into redesigning the template, only to be blocked now. Please provide any method to enable this feature through the API, whether REST or GraphQL.

ShopifyDevSup
Shopify Staff
1453 238 522

Hi @LingerLab,

 

As mentioned in our last reply above, the Product Unit Price is currently not able to be added or edited via the API. If you are needing to add this information to products, it will need to be done via the Shopify Admin. I've been gathering and submitting partner and merchant feedback to our developers regarding this current limitation and I will include your feedback as well. While we can't guarantee when or if this will be added in the future, I can guarantee that we do take all our merchants and partner's feedback to great value when considering upcoming changes to the platform!

Here is also a Shopify Help Center article with more information on adding Product Unit Prices via the Shopify Admin:

 

I hope this helps, and I hope you have a great day 🙂

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

miteshbhagwant
Shopify Partner
9 0 1

hey did you find something ?