Skip to content

This is the location for the golang sdk to be deployed for package management using go get

License

Notifications You must be signed in to change notification settings

sailpoint-oss/sailpoint-api-client-go

Repository files navigation

golang-sdk

Create your project

go mod init github.com/github-repo-name/projectname

Create sdk.go file and copy the below code into the file

package main

import (
	"context"
	"fmt"
	"os"

	sailpoint "github.com/sailpoint-oss/sailpoint-api-client-go"
)

func main() {

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

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

}

Create a configuration file or save your configuration as environment variables

You can create a local configuration file using the CLI tool or you can store your configuration in environment variables

  • SAIL_BASE_URL
  • SAIL_CLIENT_ID
  • SAIL_CLIENT_SECRET

Install sdk

go mod tidy

Run the example

go run sdk.go

Handling Pagination

there is a built in pagination function that can be used to automatically call and collect responses from APIs that support pagination. Use the following syntax to call it:

import (
	"context"
	"fmt"
	"os"

	sailpoint "github.com/sailpoint-oss/sailpoint-api-client-go"
	// need to import the v3 library so we are aware of the sailpointsdk.Account struct
	sailpointsdk "github.com/sailpoint-oss/sailpoint-api-client-go/v3"
)

func main() {

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

	// use the paginate function to get 1000 results instead of hitting the normal 250 limit
	resp, r, err := sailpoint.PaginateWithDefaults[sailpointsdk.Account](apiClient.V3.AccountsApi.ListAccounts(ctx))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `AccountsApi.ListAccount``: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}
	// response from `ListAccounts`: []Account
	fmt.Fprintf(os.Stdout, "First response from `AccountsApi.ListAccount`: %v\n", resp[0].Name)

}

About

This is the location for the golang sdk to be deployed for package management using go get

Resources

License

Stars

Watchers

Forks

Packages

No packages published