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

@david_smith , IĀ“d be pleased you if you send me the documentation. Thanks

1 Like

Sent!

@david_smith Iā€™d like to take a look at this as well. Would you be able to send this to me as well?

Iā€™ve same request : Using a CURL cmd line (in a Powershellscript) to get all my assets.
Have you find how to ?