How To: Use the GQL API to get a list of groups and the assets they contain

This post will provide guidance on which queries can be used to generate a list of groups, and assets within those groups, from your ExoSense instance. This post will assume some basic familiarity with GQL.

Query 1: assets

  • Can return a list of all assets in your instance, regardless of whether the assets are more than one-level down in the group hierarchy.

  • Top level items in the list will be assets. Your script will need to iterate over the list and sort them if you want them sorted by group.

Example Query:

query assets($pagination: Pagination) {
  assets(pagination: $pagination, includeTemplates: true) {
    id
    name
	parent {
		id
		name
	}
  }
}

Example Query Variables:

{
	"pagination": {
		"limit": 100,
		"offset": 0
	}
}

Query 2: groups

  • Top level items in the list will be group objects. Groups will not be nested by position in the hierarchy.
  • The optional parent field will return the group any given group is a member of, allowing your script to replicate the hierarchy in a nested data structure.

Example Query:

query groups($pagination: Pagination) {
  groups(pagination: $pagination) {
	name
	id
    parent {
        id
        name
    }
    assets {
		id
		name
	}
  }
}

Example Query Variables:

{
	"pagination": {
		"limit": 100,
		"offset": 0
	}
}