Assets API

Thank you :slight_smile:

@andy_robinson_platform_ux

Hello @david_smith

can you share the same document to me also.

Sent! :+1:

@david_smith, I’d like a copy as well if available. Thanks in advance

Hello David,
I would like to query all hosts with their hostnames to match them with our asset database. Unfortunately, no structure is specified in the documentation. How exactly does the query have to look like if I want to find out host names and agent status.

Here is an example query

query MyQuery {
  organization(id: "<ORG-ID-HERE>") {
    assets(first: 10000) {
      edges {
        node {
          agent {
            id
            agentSemanticVersion
            agentStatus
          }
          host {
            hostNames {
              name
            }
          }
        }
        cursor
      }
    }
  }
}



Note you can only poll for up to 10000 assets at a time, if you happen to have more than 10000 you need to use the cursor to step through the results.

Whatever string is returned from the cursor needs to be inputted into the subsequent query like so

query MyQuery {
  organization(id: "<ORG-ID-HERE>") {
    assets(first: 10000, after: "<CURSOR-VALUE-HERE>") {
       edges {
        node {
          agent {
            id
            agentSemanticVersion
            agentStatus
          }
          host {
            hostNames {
              name
            }
          }
        }
        cursor
      }
    }
  }
}


This would return the next 10000, then the new cursor would return the next 10000 and so on.

David

2 Likes

Hi David,
thank you for your help but i get an Error:

Validation error of type FieldUndefined: Field ‘bootstrap’ in type ‘Asset’ is undefined @ 'organization/assets/edges/node/bootstrap

if I Query the __schema/types i get a long list, but bootstrap is not an entry in it.

Update:
today i talked with Ryan. He helped me with finding the correct Query:

query($orgId: String!){ organization(id: $orgId) {
assets(first: 10000) {
edges {
node {
agent{
agentStatus
agentSemanticVersion
id
}
host{
hostNames{
name
}
}

    }
    cursor
  }
}

}
}

Thanks for updating, I updated my post to reflect that so no one visiting from the future gets confused, I didn’t realize we had not exposed the bootstrap via the Graphql Preview API. We have a backend for querying and mutations which is a superset of what is currently available via the Public API

David

1 Like

@david_smith - Can I also get the preview docs? I’ve been looking all over the place for a way to pull the asset information out of the Data Collection Management view without using the [Export to CSV] option.

Thanks!

@david_smith I am also looking for a way to retrieve all assets at once using call. I would love to get my hand on this documentation as well

Sent your way!

1 Like

Hi David,

I followed the documentation but for some reason I got the following error:
{“errors”:[{“message”:“Unable to validate request”}]}

Here is my code:
headers = {‘x-api-key’: API_KEY, “Content-Type”: “application/json”, “Accept-Version”: “kratos” }
url = “https://us.api.insight.rapid7.com/graphql
req = requests.post(url, headers=headers, json={‘query’: query})
print(req.status_code)
print(req.text)

Hi @tnguyen5 how are you calling this? Via Python or something else?

Yes, I am using Python

Can you confirm you can run a query successfully using a Graphql client such as Altair?

Screen Shot 2022-06-27 at 1.44.35 PM

Here’s a simply query I just ran

query MyQuery {
  organization(id: "OrgID") {
    assets(first: 10) {
      edges {
        node {
          id
        }
      }
    }
  }
}

making sure to set the headers correctly