DocsUse case

Dynamic pricing for gold jewellery shops

Keep product prices in step with the gold rate by recomputing them on a schedule and writing them to Shopify or WooCommerce.

7 Nov 2026 · 2 min read

A gold jewellery store that prices by weight has to change its product prices when gold moves. The rule is simple: price = grams × karat rate + making charge. A scheduled job fetches the rate from GET /v1/carat, recomputes each product and writes the new price to the shop. The Shopify and WooCommerce requests in the examples are printed and not sent, because a store and its IDs are needed to send them.

  • One rate request per run serves the whole catalog. Product count does not change the number of API calls.
  • Compute with Decimal, round once per product, and send the price as a string.
  • Shopify updates variants with the productVariantsBulkUpdate GraphQL mutation. WooCommerce updates regular_price on the product or variation endpoint.

Compute the prices

Each product record holds its grams, karat and making charge. The script fetches the rates once, computes every price and prints the update body for Shopify and for WooCommerce.

Shell
import jsonfrom decimal import Decimal, ROUND_HALF_UPfrom urllib.request import urlopenAPI = "https://api.goldprice.dev"cents = lambda d: d.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)with urlopen(f"{API}/v1/carat?currency=USD", timeout=10) as r:    rates = json.load(r)PRODUCTS = [  # Shopify variant id, WooCommerce product id, grams, karat, making charge    ("gid://shopify/ProductVariant/1001", 2001, "4.20", 14, "35.00"),    ("gid://shopify/ProductVariant/1002", 2002, "6.80", 18, "52.00"),]def price(grams, karat, making):    return cents(Decimal(grams) * Decimal(rates[f"price_gram_{karat}k"]) + Decimal(making))for variant_id, woo_id, grams, karat, making in PRODUCTS:    p = str(price(grams, karat, making))    shopify = {"productId": "gid://shopify/Product/<id>", "variants": [{"id": variant_id, "price": p}]}    woo = ("PUT", f"/wp-json/wc/v3/products/{woo_id}", {"regular_price": p})    print(json.dumps(shopify))    print(*woo[:2], json.dumps(woo[2]))

Run on 2 November 2026:

Shell
{"productId": "gid://shopify/Product/<id>", "variants": [{"id": "gid://shopify/ProductVariant/1001", "price": "342.52"}]}PUT /wp-json/wc/v3/products/2001 {"regular_price": "342.52"}{"productId": "gid://shopify/Product/<id>", "variants": [{"id": "gid://shopify/ProductVariant/1002", "price": "692.15"}]}PUT /wp-json/wc/v3/products/2002 {"regular_price": "692.15"}

The 14K ring at 4.20 g came to 342.52 dollars and the 18K ring at 6.80 g to 692.15 dollars.

Write the prices to Shopify

Shopify's Admin GraphQL API takes the productVariantsBulkUpdate mutation with a product id and a list of variants. Each variant carries its id and the new price. Send it to https://<store>.myshopify.com/admin/api/2026-10/graphql.json with the X-Shopify-Access-Token header.

Shell
mutation ($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {  productVariantsBulkUpdate(productId: $productId, variants: $variants) {    productVariants { id price }    userErrors { field message }  }}

The variables are the JSON objects the script printed. Read userErrors on every response.

Write the prices to WooCommerce

The WooCommerce REST API updates a product with PUT /wp-json/wc/v3/products/<id> and a JSON body that holds regular_price as a string. Variations use /products/<id>/variations/<variation id>. Authenticate with a consumer key and secret over HTTPS.

Shell
curl -X PUT https://shop.example.com/wp-json/wc/v3/products/2001 \  -u consumer_key:consumer_secret \  -H "Content-Type: application/json" \  -d '{"regular_price": "342.52"}'

Run it on a schedule

  • Cadence. A 15-minute job makes 96 requests a day to the price API, about 2,900 a month, which is inside the 5,000 requests on a free key.
  • Delay. Free and keyless prices are 15 minutes late. Paid plans return live prices.
  • Rounding. Choose a price ending, such as .00 or .95, and apply it after the sum.
  • Display. Show the update time on the product page so a customer knows how current the price is.
  • Failures. If the rate fetch fails, leave prices as they are. Do not write zero.
  • Writes. Update only the products whose price changed since the last run.

Questions

How do I update Shopify prices from a gold price?

Fetch the karat rate from `/v1/carat`, compute grams × rate + making charge, and send the result in a `productVariantsBulkUpdate` mutation.

How do I update WooCommerce prices from a gold price?

Send a `PUT` to `/wp-json/wc/v3/products/<id>` with `regular_price` set to the new price as a string. Use the variations endpoint for variable products.

How often should prices change?

Pick a refresh that matches how fast you can honour a price, such as every 15 minutes. Show the time of the last update on the product page.

Is the Free plan allowed for a shop?

Yes. The Free plan allows commercial use if you show a visible link to goldprice.dev near the prices. Paid plans need no link.

Keep reading

Reprice from a live rate

The karat endpoint needs no key. A free key adds a monthly quota for a repricing job that runs through the day.

Get a free key