Rest Api

REST API

Measurement Price Calculator includes a full REST API for headless stores, custom integrations, and programmatic access to calculator settings and pricing.

Overview

All endpoints use the mpwc/v1 namespace. The base URL is:

https://yoursite.com/wp-json/mpwc/v1/

Authentication

EndpointAuthenticationCapability
GET endpointsNone (public)-
POST /calculateNone (public)-
POST /products/{id}/calculatorRequiredmanage_woocommerce
Scroll to see all columns →
Public endpoints are available to any visitor. The save endpoint requires authentication with a user who has the manage_woocommerce capability (shop manager or administrator).

Authentication methods: Application passwords, JWT, OAuth, or cookie-based authentication all work. Use whatever method your integration supports.

Endpoints

Calculate price

Calculate the price for a product based on measurement inputs.

POST /wp-json/mpwc/v1/calculate

Parameters

ParameterTypeRequiredDescription
product_idintegerYesWooCommerce product ID
measurementsobjectYesKey-value pairs of measurement inputs
variation_idintegerNoVariation ID for variable products
Scroll to see all columns →

Example request

POST /wp-json/mpwc/v1/calculate
Content-Type: application/json

{
  "product_id": 123,
  "measurements": {
    "length": 12,
    "width": 15
  }
}

Example response

{
  "success": true,
  "calculated_measurement": 180,
  "measurement_unit": "sq ft",
  "price_per_unit": 4.25,
  "total_price": 765,
  "total_price_formatted": "$765.00",
  "overage_percentage": 10,
  "measurement_with_overage": 198,
  "surcharges": [],
  "pricing_tier": {
    "range_start": 100,
    "range_end": 499,
    "price": 4.25,
    "is_sale": false
  }
}

Response with surcharges

When conditional logic surcharges apply:

{
  "success": true,
  "calculated_measurement": 250,
  "measurement_unit": "sq ft",
  "price_per_unit": 4.25,
  "total_price": 1276.88,
  "total_price_formatted": "$1,276.88",
  "surcharges": [
    {
      "type": "percentage",
      "value": 15,
      "amount": 159.38,
      "label": "Oversize surcharge"
    }
  ]
}

Get calculator configuration

Retrieve the full calculator configuration for a product, including fields, pricing rules, conditions, and custom variables.

GET /wp-json/mpwc/v1/products/{id}/calculator

Parameters

ParameterTypeRequiredDescription
idintegerYesProduct ID (in URL)
Scroll to see all columns →

Example request

GET /wp-json/mpwc/v1/products/123/calculator

Example response

{
  "product_id": 123,
  "calculator_type": "area",
  "pricing_unit": "sq ft",
  "pricing_label": "per sq ft",
  "minimum_price": "50",
  "overage": "10",
  "fields": [
    {
      "name": "length",
      "label": "Length",
      "unit": "ft",
      "min": "1",
      "max": "100",
      "step": "0.25",
      "input_type": "free",
      "options": []
    },
    {
      "name": "width",
      "label": "Width",
      "unit": "ft",
      "min": "1",
      "max": "100",
      "step": "0.25",
      "input_type": "free",
      "options": []
    }
  ],
  "pricing_rules": [...],
  "conditions": [...],
  "custom_variables": []
}

Get pricing table

Retrieve the enriched pricing table for a product with formatted prices and sale status.

GET /wp-json/mpwc/v1/products/{id}/pricing-table

Parameters

ParameterTypeRequiredDescription
idintegerYesProduct ID (in URL)
Scroll to see all columns →

Example request

GET /wp-json/mpwc/v1/products/123/pricing-table

Example response

{
  "product_id": 123,
  "pricing_unit": "sq ft",
  "rules": [
    {
      "range_start": 1,
      "range_end": 99,
      "price": 5,
      "price_formatted": "$5.00",
      "sale_price": null,
      "sale_price_formatted": null,
      "is_sale_active": false
    },
    {
      "range_start": 100,
      "range_end": 499,
      "price": 4.25,
      "price_formatted": "$4.25",
      "sale_price": 3.99,
      "sale_price_formatted": "$3.99",
      "is_sale_active": true
    },
    {
      "range_start": 500,
      "range_end": null,
      "price": 3.5,
      "price_formatted": "$3.50",
      "sale_price": null,
      "sale_price_formatted": null,
      "is_sale_active": false
    }
  ]
}

Save calculator settings

Save calculator settings for a product. Supports partial updates (deep merge).

POST /wp-json/mpwc/v1/products/{id}/calculator

Requires authentication with manage_woocommerce capability.

Parameters

ParameterTypeRequiredDescription
idintegerYesProduct ID (in URL)
calculator_typestringNoCalculator type
settingsobjectNoSettings object (pricing_unit, pricing_label, etc.)
variablesarrayNoCustom variables array
formulastringNoCustom formula expression
pricing_rulesarrayNoPricing rules array
conditionsarrayNoConditional logic rules
Scroll to see all columns →

Example request

POST /wp-json/mpwc/v1/products/123/calculator
Authorization: Basic base64(username:application_password)
Content-Type: application/json

{
  "calculator_type": "area",
  "settings": {
    "pricing_unit": "sq ft",
    "pricing_label": "per sq ft",
    "overage": "10"
  }
}

Example response

{
  "success": true,
  "message": "Calculator settings saved.",
  "product_id": 123
}

Partial updates

Only the fields you include in the request are updated. Omitted fields keep their existing values.

Example: Update only the overage percentage:

{
  "settings": {
    "overage": "15"
  }
}

Get available units

Retrieve all available measurement units organized by type.

GET /wp-json/mpwc/v1/units

Example request

GET /wp-json/mpwc/v1/units

Example response

{
  "length": {
    "in": "inches",
    "ft": "feet",
    "yd": "yards",
    "m": "metres",
    "cm": "centimetres",
    "mm": "millimetres"
  },
  "area": {
    "sq in": "square inches",
    "sq ft": "square feet",
    "sq yd": "square yards",
    "sq m": "square metres",
    "sq cm": "square centimetres",
    "acre": "acres",
    "ha": "hectares"
  },
  "volume": {
    "cu in": "cubic inches",
    "cu ft": "cubic feet",
    "cu yd": "cubic yards",
    "cu m": "cubic metres",
    "L": "litres",
    "mL": "millilitres",
    "gal": "gallons"
  },
  "weight": {
    "oz": "ounces",
    "lb": "pounds",
    "t": "tons",
    "g": "grams",
    "kg": "kilograms"
  }
}

Error responses

All endpoints return structured error responses:

{
  "code": "invalid_product",
  "message": "Product not found or does not have a calculator enabled.",
  "data": {
    "status": 404
  }
}

Common error codes

CodeStatusDescription
invalid_product404Product not found or calculator not enabled
missing_measurements400Required measurement inputs not provided
invalid_measurement400Measurement value out of range or non-numeric
unauthorized401Authentication required for admin endpoints
forbidden403User lacks manage_woocommerce capability
Scroll to see all columns →

Use cases

Headless storefront

Build a custom frontend that fetches calculator configuration and calculates prices via the API:

  • GET /products/{id}/calculator to get fields and configuration.
  • Build your own input form.
  • POST /calculate with measurements to get the price.
  • Use WooCommerce Store API to add to cart.

Mobile app

Integrate measurement-based pricing in a mobile app:

  • GET /units to populate unit selectors.
  • GET /products/{id}/calculator for product configuration.
  • POST /calculate for real-time pricing.

Bulk configuration

Programmatically configure calculator settings for many products:

  • POST /products/{id}/calculator for each product.
  • Supports partial updates for efficiency.

Price comparison widget

Display pricing tiers from another system:

  • GET /products/{id}/pricing-table to get formatted pricing data.
  • Render in your own UI.

Rate limiting

The API does not impose its own rate limits. Standard WordPress and server-level rate limiting applies. For bulk operations, add a small delay between requests.

Best practices

  • Cache GET responses when possible. Calculator configuration rarely changes.
  • Use partial updates for the save endpoint. Only send fields that changed.
  • Validate client-side before calling POST /calculate. The API validates too, but client-side validation improves UX.
  • Handle errors gracefully. Always check for error responses and display meaningful messages.
  • Use application passwords for server-to-server authentication. They're built into WordPress and easy to manage.