diff --git a/products/idn/tools/sdk/go.mdx b/products/idn/tools/sdk/go.mdx index 308c99d520b..0f9c820a4f1 100644 --- a/products/idn/tools/sdk/go.mdx +++ b/products/idn/tools/sdk/go.mdx @@ -264,11 +264,11 @@ func main() { resp, r, err := sailpoint.PaginateWithDefaults[v3.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, "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 `AccountsApi.ListAccount`: %v\n", resp[0].Name) + fmt.Fprintf(os.Stdout, "First response from `PaginateWithDefaults[v3.Account]`: %v\n", resp[0].Name) } ``` @@ -296,11 +296,11 @@ func main() { 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 `AccountsApi.ListAccount``: %v\n", err) + 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 `AccountsApi.ListAccount`: %v\n", resp[0].Name) + fmt.Fprintf(os.Stdout, "First response from `Paginate[v3.Account]`: %v\n", resp[0].Name) } ``` @@ -330,7 +330,7 @@ func getSearchResults(ctx context.Context, apiClient *sailpoint.APIClient) { search.UnmarshalJSON(searchString) resp, r, err := sailpoint.PaginateSearchApi(ctx, apiClient, *search, 0, 10, 10000) if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `AccountsApi.ListAccount``: %v\n", err) + fmt.Fprintf(os.Stderr, "Error when calling `PaginateSearchApi``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `search` @@ -411,12 +411,37 @@ func main() { resp, r, err := apiClient.V3.TransformsApi.ListTransforms(ctx).Filters("This is an incorrect string").Execute() if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `AccountsApi.ListAccount``: %v\n", err) + fmt.Fprintf(os.Stderr, "Error when calling `TransformsApi.ListTransforms``: %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) + fmt.Fprintf(os.Stdout, "First response from `TransformsApi.ListTransforms`: %v\n", resp) + +} +``` + +### Error Handling + +The SDK returns the response object, request and error object for each method. The error object will be defined for any response status that falls out of the range of 2xx. + +Using an if statement we can check if there are any errors with the request and take actions on the results, such as logging the message or performing additional actions before exiting the program. +```go +resp, r, err := apiClient.V3.TransformsApi.ListTransforms(ctx).Filters("This is an incorrect string").Execute() +if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `TransformsApi.ListTransforms``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) +} +``` + +The program will continue running unless you specify to end it. Use `os.Exit(0)` within the error check to stop execution after an error is found. + +```go +resp, r, err := apiClient.V3.TransformsApi.ListTransforms(ctx).Filters("This is an incorrect string").Execute() +if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `TransformsApi.ListTransforms``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + os.Exit(0) } ``` diff --git a/products/idn/tools/sdk/powershell.mdx b/products/idn/tools/sdk/powershell.mdx index cf0727968e7..5fe557e9c0a 100644 --- a/products/idn/tools/sdk/powershell.mdx +++ b/products/idn/tools/sdk/powershell.mdx @@ -300,6 +300,20 @@ Running `Get-Transforms` will return a list of all transforms in your tenant. Running `Get-Transforms -Limit 10 -Filter 'name sw Test"'` will return a list of no more than 10 transforms whose names start with `Test`. +### WithHttpInfo Switch + +By default, the cmdlets return just the response from the API without including any information about status code or headers returned. Use the `-WithHttpInfo` switch to return this information with the response. + +```powershell +Get-Transforms -WithHttpInfo + +Name Value +---- ----- +Headers {[Date, System.String[]], [Transfer-Encoding, System.String[]], [Connection, System.String[]], [Server, System.String[]]…} +StatusCode 200 +Response {System.Management.Automation.OrderedHashtable, System.Management.Automation.OrderedHashtable, System.Management.Automation.Ordered… +``` + ### Paginate Results 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](/idn/api/standard-collection-parameters/#paginating-results). @@ -429,6 +443,41 @@ The following code will tell the SDK to retry 2 times after an unexpected error Set-DefaultConfiguration -MaximumRetryCount 2 -RetryIntervalSeconds 3 ``` +### Error Handling + +The SDK uses the Invoke-WebRequest cmdlet to handle HTTP requests. Invoke-WebRequest will throw a terminating error for any response that falls out of the range of 2xx. A non-2xx response will immediately halt the program and produce a stack trace. + +Using a try/catch function, you can intercept any non success response and take actions on the results, such as logging the message or performing additional actions before exiting the program. + +```powershell +# Catch any non 2xx response and log the status code and error message +try { + Get-Transforms -Filters "id eq" +} +catch { + Write-Host $_.Exception.Response.StatusCode.value__ + Write-Host $_.ErrorDetails +} +``` + +Using the catch block will handle the error and the script execution will continue. If you wish to stop the scripts execution, include an `Exit` in the catch block. + +In the following code, the `Get-AccessProfiles` cmdlet will never be called. + +```powershell +# Catch any non 2xx response and log the status code and error message. Stop the script with the Exit keyword. +try { + Get-Transforms -Filters "id eq" +} +catch { + Write-Host $_.Exception.Response.StatusCode.value__ + Write-Host $_.ErrorDetails + Exit +} + +Get-AccessProfiles +``` + ## Discuss You can use this SDK to build new tools that extend your IDN platform and improve experiences across your organization. Use this guide to get started, and if you have questions, don't hesitate to reach out on the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss! \ No newline at end of file