Files
developer.sailpoint.com/docs/tools/sdk/go/pagination.md
darrell-thobe-sp 2cd5ccfc81 Prettified Code!
2024-04-18 10:31:05 +00:00

2.6 KiB

id, title, pagination_label, sidebar_label, sidebar_position, sidebar_class_name, keywords, description, slug, tags
id title pagination_label sidebar_label sidebar_position sidebar_class_name keywords description slug tags
go-sdk-paginate Paginate results with the Go SDK Go SDK Paginate Results 5 gosdk
go
golang
sdk
paginate
Learn how to paginate results with the Golang SDK in this guide. /tools/sdk/go/paginate
SDK
Software Development Kit

By default, your requests will return a maximum of 250 records. To return more, you must implement pagination. To learn more about pagination, refer to Paginating Results.

Pagination is implemented with the SDK in the following code block on line 18:

package main

import (
 "context"
 "fmt"
 "os"

 sailpoint "github.com/sailpoint-oss/golang-sdk"
 v3 "github.com/sailpoint-oss/golang-sdk/v3"
)

func main() {

 ctx := context.TODO()
 configuration := sailpoint.NewDefaultConfiguration()
 apiClient := sailpoint.NewAPIClient(configuration)

 resp, r, err := sailpoint.PaginateWithDefaults[v3.Account](apiClient.V3.AccountsApi.ListAccounts(ctx))
 if err != nil {
  fmt.Fprintf(os.Stderr, "Error when calling `PaginateWithDefaults[v3.Account]``: %v\n", err)
  fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
 }
 // response from `ListAccounts`: []Account
 fmt.Fprintf(os.Stdout, "First response from `PaginateWithDefaults[v3.Account]`: %v\n", resp[0].Name)
}

The PaginateWithDefaults function takes a return type, v3.Account, and the list method to invoke, in this case ListAccounts from the AccountsApi. By default, the PaginateWithDefaults method gets 10000 results at an increment of 250.

To change the limit and increment, you can use the available 'Paginate' function:

package main

import (
 "context"
 "fmt"
 "os"

 sailpoint "github.com/sailpoint-oss/golang-sdk"
 v3 "github.com/sailpoint-oss/golang-sdk/v3"
)

func main() {

 ctx := context.TODO()
 configuration := sailpoint.NewDefaultConfiguration()
 apiClient := sailpoint.NewAPIClient(configuration)

 resp, r, err := sailpoint.Paginate[v3.Account](apiClient.V3.AccountsApi.ListAccounts(ctx), 0, 250, 150000)
 if err != nil {
  fmt.Fprintf(os.Stderr, "Error when calling `Paginate[v3.Account]``: %v\n", err)
  fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
 }
 // response from `ListAccounts`: []Account
 fmt.Fprintf(os.Stdout, "First response from `Paginate[v3.Account]`: %v\n", resp[0].Name)
}

You must provide the Paginate function with the following: the return type, v3.Account, the list endpoint, ListAccounts, the initial offset, 0, the increment, 250, and the limit, 150000.