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

2.2 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-patch Updating resources with the Go SDK Go SDK Update a resource 3 gosdk
go
golang
sdk
update
Learn how to update resources with the Golang SDK. /tools/sdk/go/update
SDK
Software Development Kit

Here is an example update WorkGroup script which will update the description for the previously created Workgroup from Create a Resource:

package main

import (
 "context"
 "encoding/json"
 "fmt"
 "os"

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

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)
 }

 updatedDescription := `This is an updated description for the workgroup.`
 newDescriptionValue := beta.JsonPatchOperationValue{String: &updatedDescription}
 patchArray := []beta.JsonPatchOperation{{Op: "replace", Path: "/description", Value: &newDescriptionValue}}

 updatedWorkgroup, request, errorMessage := apiClient.Beta.GovernanceGroupsApi.PatchWorkgroup(ctx, *workgroup[0].Id).JsonPatchOperation(patchArray).Execute()

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

 b, _ := json.MarshalIndent(updatedWorkgroup, "", "  ")
 fmt.Fprint(os.Stdout, string(b))

}

To run the code, run this command:

go run sdk.go

The updated WorkGroup will be returned by the SDK:

{
  "created": "2023-12-04T19:37:28Z",
  "description": "This is an updated description for the workgroup.",
  "modified": "2023-12-04T19:37:28Z",
  "name": "DB Access Governance Group",
  "owner": {
    "displayName": "Brian Mendoza",
    "emailAddress": null,
    "id": "0003c25c365e492381d4e557b6159f9b",
    "name": "Brian Mendoza",
    "type": "IDENTITY"
  }
}