Auto-approve an expense claim when it is under the role limit and has a valid category.
A **expense** is approved
if the __amount__ of the **expense** is less than or equal to the __approval_limit__ of the **employee**
and the __category__ of the **expense** is in ["travel", "meals", "software", "equipment", "training"]
and the __has_receipt__ of the **expense** is equal to true.
{
"properties": {
"expense": {
"properties": {
"amount": {
"type": "number"
},
"category": {
"type": "string"
},
"has_receipt": {
"type": "boolean"
}
},
"required": [
"amount",
"category",
"has_receipt"
],
"type": "object"
},
"employee": {
"properties": {
"approval_limit": {
"type": "number"
}
},
"required": [
"approval_limit"
],
"type": "object"
}
},
"required": [
"expense",
"employee"
],
"title": "Expense Model",
"type": "object"
}Within limit with receipt
Expect pass{
"expense": {
"amount": 75,
"category": "meals",
"has_receipt": true
},
"employee": {
"approval_limit": 200
}
}Over limit
Expect fail{
"expense": {
"amount": 500,
"category": "equipment",
"has_receipt": true
},
"employee": {
"approval_limit": 200
}
}Execute this policy from your app using one of the official SDKs.
import { ExecutionClient } from "@policies2/sdk";
const client = new ExecutionClient({
apiKey: process.env.POLICY_API_KEY!,
transport: { kind: "rest", baseUrl: "https://api.policy2.net" },
});
const result = await client.executePolicy({
id: "your-policy-id", // replace with your published policy ID
reference: "base",
data: {
"expense": {
"amount": 75,
"category": "meals",
"has_receipt": true
},
"employee": {
"approval_limit": 200
}
},
});
if (result.result) {
console.log("policy matched");
} else {
console.log("policy did not match");
}Ready to try this policy?
Open in editor