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
| Endpoint | Authentication | Capability |
|---|---|---|
GET endpoints | None (public) | - |
POST /calculate | None (public) | - |
POST /products/{id}/calculator | Required | manage_woocommerce |
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
| Parameter | Type | Required | Description |
|---|---|---|---|
product_id | integer | Yes | WooCommerce product ID |
measurements | object | Yes | Key-value pairs of measurement inputs |
variation_id | integer | No | Variation ID for variable products |
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
| Parameter | Type | Required | Description |
|---|---|---|---|
id | integer | Yes | Product ID (in URL) |
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
| Parameter | Type | Required | Description |
|---|---|---|---|
id | integer | Yes | Product ID (in URL) |
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
| Parameter | Type | Required | Description |
|---|---|---|---|
id | integer | Yes | Product ID (in URL) |
calculator_type | string | No | Calculator type |
settings | object | No | Settings object (pricing_unit, pricing_label, etc.) |
variables | array | No | Custom variables array |
formula | string | No | Custom formula expression |
pricing_rules | array | No | Pricing rules array |
conditions | array | No | Conditional logic rules |
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
| Code | Status | Description |
|---|---|---|
invalid_product | 404 | Product not found or calculator not enabled |
missing_measurements | 400 | Required measurement inputs not provided |
invalid_measurement | 400 | Measurement value out of range or non-numeric |
unauthorized | 401 | Authentication required for admin endpoints |
forbidden | 403 | User lacks manage_woocommerce capability |
Use cases
Headless storefront
Build a custom frontend that fetches calculator configuration and calculates prices via the API:
GET /products/{id}/calculatorto get fields and configuration.- Build your own input form.
POST /calculatewith measurements to get the price.- Use WooCommerce Store API to add to cart.
Mobile app
Integrate measurement-based pricing in a mobile app:
GET /unitsto populate unit selectors.GET /products/{id}/calculatorfor product configuration.POST /calculatefor real-time pricing.
Bulk configuration
Programmatically configure calculator settings for many products:
POST /products/{id}/calculatorfor each product.- Supports partial updates for efficiency.
Price comparison widget
Display pricing tiers from another system:
GET /products/{id}/pricing-tableto 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.