import weflayr
from weflayr.openapi.models import MarginInput
client = weflayr.client() # reads WEFLAYR_API_KEY
client.get_margin(body=MarginInput.from_dict({
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"],
}))
const weflayr = require('weflayr');
const client = weflayr.client(); // reads WEFLAYR_API_KEY
await weflayr.api.getMargin({
client,
throwOnError: true,
body: {
dateFrom: '2026-06-01',
aggregate: 'week',
groupBy: 'customer',
customers: ['c_123', 'c_456'],
},
});
curl -X POST https://app.weflayr.com/api/margin/ \
-H "Authorization: Bearer $WEFLAYR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"]
}'
{
"rows": [
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_123", "revenue": 1200.5, "cost": 420.0, "margin": 780.5, "margin_pct": 65.02, "risk_status": "healthy"},
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_456", "revenue": 800.0, "cost": 950.0, "margin": -150.0, "margin_pct": -18.75, "risk_status": "unprofitable"}
],
"next_cursor": null,
"has_more": false
}
Dashboard data
Get margin
Get cost and revenue, bucketed by period and optionally grouped by customer, alongside the resulting margin and risk status.
POST
/
api
/
margin
/
import weflayr
from weflayr.openapi.models import MarginInput
client = weflayr.client() # reads WEFLAYR_API_KEY
client.get_margin(body=MarginInput.from_dict({
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"],
}))
const weflayr = require('weflayr');
const client = weflayr.client(); // reads WEFLAYR_API_KEY
await weflayr.api.getMargin({
client,
throwOnError: true,
body: {
dateFrom: '2026-06-01',
aggregate: 'week',
groupBy: 'customer',
customers: ['c_123', 'c_456'],
},
});
curl -X POST https://app.weflayr.com/api/margin/ \
-H "Authorization: Bearer $WEFLAYR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"]
}'
{
"rows": [
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_123", "revenue": 1200.5, "cost": 420.0, "margin": 780.5, "margin_pct": 65.02, "risk_status": "healthy"},
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_456", "revenue": 800.0, "cost": 950.0, "margin": -150.0, "margin_pct": -18.75, "risk_status": "unprofitable"}
],
"next_cursor": null,
"has_more": false
}
Margin is computed on revenue-linked projects (the default project type). On an internal project (tracked by key metrics, not revenue), this route returns a 400: use Get performance instead.
customer is omitted when group_by isn’t set.
Parameters
Passed in the request body."YYYY-MM-DD"
required
Start of the period, inclusive.
"YYYY-MM-DD"
End of the period, inclusive. Defaults to today.
"day" | "week" | "month" | "quarter" | "year" | "all"
default:"\"day\""
One row per period;
"all" collapses the whole date range into a single row (per group_by, if set)."customer"
Split each period into one row per customer. Omit for one row per period.
list[string]
Restrict to these customers. Omit for every customer’s. See Get customers.
list[string]
Restrict to customers who used any of these feature tags in the period (i.e. if a customer did not use the feature, all its rows are removed).
boolean
default:"false"
Apply free AI credits discounts to
cost.integer
default:"100"
Max number of rows to fetch. Max
1000.string
The route is paginated: pass the previous page’s
next_cursor to fetch the next page. PS: has_more from the output says whether another page exists.import weflayr
from weflayr.openapi.models import MarginInput
client = weflayr.client() # reads WEFLAYR_API_KEY
client.get_margin(body=MarginInput.from_dict({
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"],
}))
const weflayr = require('weflayr');
const client = weflayr.client(); // reads WEFLAYR_API_KEY
await weflayr.api.getMargin({
client,
throwOnError: true,
body: {
dateFrom: '2026-06-01',
aggregate: 'week',
groupBy: 'customer',
customers: ['c_123', 'c_456'],
},
});
curl -X POST https://app.weflayr.com/api/margin/ \
-H "Authorization: Bearer $WEFLAYR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"]
}'
{
"rows": [
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_123", "revenue": 1200.5, "cost": 420.0, "margin": 780.5, "margin_pct": 65.02, "risk_status": "healthy"},
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_456", "revenue": 800.0, "cost": 950.0, "margin": -150.0, "margin_pct": -18.75, "risk_status": "unprofitable"}
],
"next_cursor": null,
"has_more": false
}