Skip to main content

Delete resources with the Go SDK

Here is an example script that searches for the Workgroup created in Create a resource by name and calls the delete method to remove it from your environment.

package main

import (
"context"
"fmt"
"os"

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

func main() {

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

workgroup, r, err := apiClient.Beta.GovernanceGroupsApi.ListWorkgroups(ctx).Filters(`name eq "DB Access Governance Group"`).Execute()

if err != nil {
fmt.Fprintf(os.Stderr, "Error when retrieving workgroup`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}

response, errorMessage := apiClient.Beta.GovernanceGroupsApi.DeleteWorkgroup(ctx, *workgroup[0].Id).Execute()

if errorMessage != nil {
fmt.Fprintf(os.Stderr, "Error when updating workgroup`: %v\n", errorMessage)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", response)
}

fmt.Fprintf(os.Stdout, "Resource Deleted: %v\n", response.StatusCode)

}

To run the code, run this command:

go run sdk.go

The deletionStatus is returned by the SDK with a value of 204.