Skip to main content
Version: v2.0

Aggregation API overview

info

ServiceNow's official name for this API is the Aggregate API; the SDK module is named aggregationapi. The underlying endpoint is /api/now/stats, which is why the fluent accessor is Now().Stats(...).

The Aggregation API returns aggregate statistics (count, sum, average, minimum, maximum) computed over the records of a table, without returning the records themselves.

note

This module currently supports the ungrouped shape of the API only: one aggregate result per request. sysparm_group_by / sysparm_having aren't yet modeled.

Basic usage

Access it through the Now() namespace:

wantCount := true
statsQuery := "active=true"
config := &aggregationapi.StatsRequestBuilderGetRequestConfiguration{
QueryParameters: &aggregationapi.StatsRequestBuilderGetQueryParameters{
Count: &wantCount,
SumFields: []string{"reassignment_count"},
Query: &statsQuery,
},
}

response, err := client.Now().Stats("incident").Get(context.Background(), config)
if err != nil {
log.Fatal(err)
}

result, err := response.GetResult()
if err != nil {
log.Fatal(err)
}

stats, err := result.GetStats()
if err != nil {
log.Fatal(err)
}

count, _ := stats.GetCount()

Available operations

  • Get aggregatesStats(tableName).Get(ctx, config) with query parameters selecting the aggregates (Count, SumFields, AvgFields, MinFields, MaxFields) and an encoded Query to filter the input records.
Was this page helpful?