How to raise a variation through the API
Use the API to raise a variation when another system, or an AI agent, works out the change in scope and you want it priced in Drum. The API makes and fills in the draft. A person then submits and approves it in Drum, because those steps are not in the API.
Before you begin
You need:
- An API token (see Create an API token) whose role has
api_read,api_createandapi_update, andapi_deleteif you will remove rows. - In Drum,
create_budgetsandupdate_budgets, or a project role on the project withupdate_budgets, and read access to the project. To read the variation back,read_budgetsor a project role withview_budgets. - The project id. For
https://app.getdrum.com/projects/20488, the id is20488.
The examples keep the token in DRUM_API_TOKEN.
1. Read the budget
curl -H "Authorization: Bearer $DRUM_API_TOKEN" \
"https://app.getdrum.com/api/v1/projects/20488?include=budget_lines"
Note the ids you will change: each task’s id, and the id of each expense line in its budget_lines (kind: "cost"). The budget lines show only approved variations, so this is the budget the new variation starts from.
2. Make a draft
curl -X POST "https://app.getdrum.com/api/v1/projects/20488/variations" \
-H "Authorization: Bearer $DRUM_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "Extra levels", "description": "Two more levels of documentation", "variation_scope": "external"}'
Keep variation.id from the answer. The examples use 731.
If the answer is 422 variation_opportunity_required, the project sells its variations through an opportunity. Raise this variation in Drum, which makes the opportunity as well.
3. Change an existing task
Add a task change, then set how much the task’s quantity changes:
curl -X POST "https://app.getdrum.com/api/v1/projects/20488/variations/731/task_changes" \
-H "Authorization: Bearer $DRUM_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"task_id": 81231, "quantity_delta": 24}'
quantity_delta can be negative to take work out. The row in the answer has budget_before, budget_change and budget_after.
For a dynamic task, which is priced by its resource lines, add a resource change instead and set delta_quantity on it with a PATCH:
curl -X POST "https://app.getdrum.com/api/v1/projects/20488/variations/731/resource_changes" \
-H "Authorization: Bearer $DRUM_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"task_id": 81240, "resource_type_id": 3}'
4. Add new work
Add a task to an existing deliverable. It starts dynamic, so its price comes from its lines:
curl -X POST "https://app.getdrum.com/api/v1/projects/20488/variations/731/tasks" \
-H "Authorization: Bearer $DRUM_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"deliverable_id": 3310, "name": "Level 5 and 6 documentation", "contingency_percent": 10}'
For a whole new stage, POST .../variations/731/deliverables with a name adds a deliverable with one task.
5. Add an expense
An expense line goes on a task the variation adds, or on an existing task that it already changes (step 3):
curl -X POST "https://app.getdrum.com/api/v1/projects/20488/variations/731/costs" \
-H "Authorization: Bearer $DRUM_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"task_id": 81231, "name": "Printing", "quantity": 2, "billable_rate_cents": 15000, "markup_percent": 15}'
On an existing task with no task change, the answer is 422 task_not_varied. Do step 3 first.
To change an existing expense line instead, POST .../cost_changes with its budget_cost_id, and quantity_delta or variation_type: "removal".
6. Check the variation
curl -H "Authorization: Bearer $DRUM_API_TOKEN" \
"https://app.getdrum.com/api/v1/projects/20488/variations/731"
variation.budget_change is the change to the internal budget, and variation.contract_change the change to the client price, with contingency and markup. Each row shows its own change. Fix a row with a PATCH to its path, or remove it with a DELETE.
7. Hand it over
Ask the person who approves variations to open the variation in Drum, check it, and submit and approve it. Once it is approved, its rows join the budget, and further changes go through Project budgets or a new variation.