Skip to Content
GraphQL API

Make Your First Mondoo API Request

Send a GraphQL query to the Mondoo API with curl, Python, or JavaScript, and read the response.

This page walks you through one request that reads a space's name and its first five assets. It uses only standard tools: curl and jq, the Python standard library, or the fetch function built into Node.js.

Before you begin

  • Create an API token for a space or organization, with at least the Viewer role, and export it as MONDOO_API_TOKEN.
  • Get the MRN of the space you want to query. Open the space in the Mondoo App and go to Settings > General. Copy the value of the Space MRN field, which looks like //captain.api.mondoo.app/spaces/YOUR_SPACE_ID.
  • For the curl examples, install jq. The examples use it to build the JSON request body and to format the response.

The examples use the US endpoint. If your organization is in the EU region, use https://eu.api.mondoo.com/query instead.

The query

A single GraphQL request can ask for several things at once. This query asks for the space's name and for the total number of assets in the space, plus the name and MRN of the first five:

query FirstRequest($spaceMrn: String!) {
  space(mrn: $spaceMrn) {
    name
  }
  assets(scopeMrn: $spaceMrn, first: 5) {
    totalCount
    edges {
      node {
        name
        mrn
      }
    }
  }
}

$spaceMrn is a variable. You send its value separately, in the variables object of the request body, so you never have to edit the query text itself.

Send the request

QUERY='
query FirstRequest($spaceMrn: String!) {
  space(mrn: $spaceMrn) {
    name
  }
  assets(scopeMrn: $spaceMrn, first: 5) {
    totalCount
    edges {
      node {
        name
        mrn
      }
    }
  }
}'
VARIABLES='{"spaceMrn": "//captain.api.mondoo.app/spaces/YOUR_SPACE_ID"}'

curl -s https://us.api.mondoo.com/query \
  -H "Authorization: Bearer $MONDOO_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg query "$QUERY" --argjson variables "$VARIABLES" '{query: $query, variables: $variables}')" | jq

The last command is the same for every request in this section. Only QUERY and VARIABLES change.

Read the response

A successful response has a data object shaped like the query:

{
  "data": {
    "space": {
      "name": "Production"
    },
    "assets": {
      "totalCount": 42,
      "edges": [
        {
          "node": {
            "name": "web-01",
            "mrn": "//assets.api.mondoo.app/spaces/YOUR_SPACE_ID/assets/YOUR_ASSET_ID"
          }
        }
      ]
    }
  }
}

If the response has an errors array instead, or alongside data, read Errors.

Next steps

Last updated on

On this page