An alert is a task, and a task belongs on the board
Plenty of teams already turn their production alerts into tasks. A monitoring rule fires, a small function calls the Decuga task API with the alert's text and a priority, and a task appears for whoever is on call. That works well until you want the task to land on the sprint board, in the New column, where the team looks every morning. A task only goes on the board when it is in a sprint, and a sprint is something that changes every two weeks.
The id that kept going stale
To put a task in a sprint you send that sprint's id as sprintId. The first version of such a script holds the id in a setting. It works for the rest of the sprint, and then it does not: the sprint is completed, a new one starts, the id in the script points at a finished sprint, and the alerts stop showing up on the board until somebody notices and edits the code. The fix people reach for is to ask Decuga which sprint is active, and until now the only route that answered that was the app's own, which a script with an API key cannot call.
What the sprints API gives you
Two read-only calls, on the same project API key as the task API, on the Business plan and above. The key acts as the person who made it, so the script sees the sprints that person can see.
| Call | What it does |
|---|---|
| GET /sprints | The project's sprints, newest first, at most 100, each with its status. Send ?status=ACTIVE (or PLANNING, or COMPLETED) to get only those in one status, and ?limit= for fewer |
| GET /sprints/{sprint} | One sprint, by its id; a sprint of another project is a 404 |
An alert that lands in the right sprint
The script asks which sprint is active each time, so nothing is held in a setting.
- 1An alert fires
Your monitoring calls your function with the alert's text.
- 2Ask for the active sprint
GET /sprints?status=ACTIVE with the API key.
- 3Create the task
POST /tasks with sprintId set to that sprint's id.
- 4It is on the board
In the New column of the running sprint.
The next sprint is found the same way: nothing to update by hand
What a sprint looks like
Each sprint has an id, a name, a goal, a status, a planned start and end date, a velocity and the times it was created and completed. The status is PLANNING for a sprint that is made but not started, ACTIVE for one that is running and COMPLETED for one that is finished. Velocity, the story points finished in the sprint, is worked out when it is completed and is empty until then, and so is completedAt.
A function that finds the sprint and creates the task
Here is the whole idea in a few lines of Node, the kind a Google Cloud Function would hold. It takes the first active sprint, and creates the task in the backlog when none is running.
const base = `https://decuga.com/api/v1/projects/${process.env.DECUGA_PROJECT_ID}`
const headers = { Authorization: `Bearer ${process.env.DECUGA_API_KEY}`, 'Content-Type': 'application/json' }
export async function createAlertTask(alert) {
const sprints = await (await fetch(`${base}/sprints?status=ACTIVE`, { headers })).json()
const task = { title: alert.title, description: alert.text, priority: 'HIGH' }
if (sprints.length > 0) task.sprintId = sprints[0].id
const res = await fetch(`${base}/tasks`, { method: 'POST', headers, body: JSON.stringify(task) })
if (!res.ok) throw new Error(`Decuga answered ${res.status}`)
return res.json()
}Why it answers with a list
Asking for the active sprint gives you a list, not one sprint, and that is deliberate. A software project runs one sprint at a time, but a project made from the Marketing or the HR template can have several waves or cohorts running together, and a single answer would hide the others. An empty list means nothing is running, which is the moment your script chooses between the backlog and waiting. If your project has several active at once and you need one, pick by name or by start date in your code.
Good to know
The key needs to belong to someone who is a member of the project, like every call of the API. An unknown status is refused with a 400 that names the three allowed. The list is not paged: one call returns at most 100 sprints, the newest first, and ?limit= asks for fewer. Rate limits are the ones of the task API, shown in the headers of every answer.
What it does not do
It only reads. You cannot create, start or complete a sprint over the API: that stays in the app, where the rules about the one active sprint and the tasks that move on completion are applied with a person watching. There is no shortcut route for "the" active sprint for the reason above, and no sprint field on a task that says whether its sprint is running; ask for the sprint when you need to know. If something else would make your automation simpler, tell us. We build from customer requests, and most are closed in a day or two.