Skip to main content

API Reference

Exporting risks

Risks are exported using the risks_paged query. Scores and treatment decisions belong to individual assessments. The CSV uses the most recently approved assessment for each risk and leaves those columns blank until an assessment is approved.

Basic query

query ExportRisks($first: Int, $after: String, $filter: RiskFilter) {
  risks_paged(first: $first, after: $after, filter: $filter) {
    edges {
      node {
        id
        sequenceId
        customId
        name
        description
        notBefore
        expires
        archived
        assessments {
          approvalDate
          likelihood
          impact
          residualLikelihood
          residualImpact
          treatment
          treatmentNotes
        }
        appetite
        controls {
          id
          sequenceId
          name
        }
        assets {
          id
          name
        }
        assignments {
          assignmentType
          assignee {
            name
            email
          }
        }
        attributes {
          key
          value
        }
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

Variables to fetch the first page:

{ "first": 50, "after": null, "filter": {} }

Key fields

  • sequenceId: the human-readable number shown in the UI (e.g. R-42)
  • customId: optional custom identifier set by your team
  • assessments[].likelihood / assessments[].impact: inherent risk scores
  • assessments[].residualLikelihood / assessments[].residualImpact: residual risk scores after controls
  • assessments[].treatment: one of ACCEPT, AVOID, TRANSFER, REDUCE
  • appetite: the organisation's risk appetite score for this risk

Complete export script (Python)

This script authenticates, pages through every risk record, and writes the result to a CSV file:

import requests
import csv
from datetime import datetime
import sys

GRAPHQL_URL = "https://portal.tidalcontrol.com/graphql"

QUERY = """
query ExportRisks($first: Int, $after: String, $filter: RiskFilter) {
  risks_paged(first: $first, after: $after, filter: $filter) {
    edges {
      node {
        id
        sequenceId
        customId
        name
        description
        notBefore
        expires
        archived
        assessments {
          approvalDate
          likelihood
          impact
          residualLikelihood
          residualImpact
          treatment
          treatmentNotes
        }
        appetite
        controls { id name }
        assets { id name }
        assignments { assignmentType assignee { name email } }
      }
    }
    pageInfo { hasNextPage endCursor }
  }
}
"""


def graphql(query, variables, access_token):
    r = requests.post(
        GRAPHQL_URL,
        json={"query": query, "variables": variables},
        headers={"Authorization": f"Bearer {access_token}"},
    )
    r.raise_for_status()
    result = r.json()
    if "errors" in result:
        raise RuntimeError(result["errors"])
    return result["data"]


def export_risks(access_token, include_archived=False):
    risks = []
    cursor = None
    risk_filter = {} if include_archived else {"archived": False}

    while True:
        data = graphql(
            QUERY,
            {"first": 50, "after": cursor, "filter": risk_filter},
            access_token,
        )
        page = data["risks_paged"]
        risks.extend(edge["node"] for edge in page["edges"])

        if not page["pageInfo"]["hasNextPage"]:
            break
        cursor = page["pageInfo"]["endCursor"]

    return risks


def to_csv(risks, output_path):
    if not risks:
        print("No risks found.")
        return

    with open(output_path, "w", newline="", encoding="utf-8") as f:
        writer = csv.writer(f)
        writer.writerow([
            "ID", "Sequence ID", "Custom ID", "Name", "Description",
            "Not Before", "Expires", "Archived",
            "Likelihood", "Impact", "Residual Likelihood", "Residual Impact",
            "Treatment", "Treatment Notes", "Appetite",
            "Controls", "Assets", "Owners",
        ])
        for r in risks:
            approved = [a for a in r["assessments"] if a["approvalDate"]]
            assessment = max(
                approved,
                key=lambda a: datetime.fromisoformat(a["approvalDate"].replace("Z", "+00:00")),
                default={},
            )
            owners = [
                a["assignee"]["email"]
                for a in r["assignments"]
                if a["assignmentType"] == "OWNER"
            ]
            writer.writerow([
                r["id"],
                r["sequenceId"],
                r.get("customId", ""),
                r["name"],
                r.get("description", ""),
                r.get("notBefore", ""),
                r.get("expires", ""),
                r["archived"],
                assessment.get("likelihood", ""),
                assessment.get("impact", ""),
                assessment.get("residualLikelihood", ""),
                assessment.get("residualImpact", ""),
                assessment.get("treatment", ""),
                assessment.get("treatmentNotes", ""),
                r.get("appetite", ""),
                ", ".join(c["name"] for c in r["controls"]),
                ", ".join(a["name"] for a in r["assets"]),
                ", ".join(owners),
            ])

    print(f"Exported {len(risks)} risks to {output_path}")


if __name__ == "__main__":
    # Paste your access token here, or load it from the authentication script
    ACCESS_TOKEN = "eyJhbGci..."

    risks = export_risks(ACCESS_TOKEN)
    to_csv(risks, "risks_export.csv")

Filtering examples

Pass a filter argument to narrow the export. These are the combinations asked for most often:

Only active (non-archived) risks:

{ "filter": { "archived": false } }

Risks with treatment REDUCE:

{ "filter": { "treatment": ["REDUCE"] } }

Risks assigned to a specific person:

{ "filter": { "assignees": ["person-uuid-here"] } }

Risks linked to a specific framework:

{ "filter": { "frameworks": ["framework-uuid-here"] } }
Info

Use persons for personnel IDs and frameworks_paged for framework IDs.

Count only

To check how many risks exist before exporting:

query {
  risks_count(filter: { archived: false })
}