diff --git a/docusaurus.config.js b/docusaurus.config.js index f487a8c8222..fa019fd75f4 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -77,7 +77,7 @@ const config = { prism: { theme: lightCodeTheme, darkTheme: darkCodeTheme, - additionalLanguages: ['http', 'java', 'ruby', 'php', 'csharp'], + additionalLanguages: ['http', 'java', 'ruby', 'php', 'csharp', 'powershell', 'bash', 'go', 'python'], }, mermaid: { options: { diff --git a/products/idn/tools/sdk/go.md b/products/idn/tools/sdk/go.md.old similarity index 99% rename from products/idn/tools/sdk/go.md rename to products/idn/tools/sdk/go.md.old index 68f23acefd8..b84e89e9c28 100644 --- a/products/idn/tools/sdk/go.md +++ b/products/idn/tools/sdk/go.md.old @@ -70,7 +70,7 @@ Create an "sdk.go" file in your project and copy this code example into the file package main import ( - "context"` + "context" "fmt" "os" diff --git a/products/idn/tools/sdk/go.mdx b/products/idn/tools/sdk/go.mdx new file mode 100644 index 00000000000..42389332107 --- /dev/null +++ b/products/idn/tools/sdk/go.mdx @@ -0,0 +1,394 @@ +--- +id: go-sdk +title: Go SDK +pagination_label: Go SDK +sidebar_label: Golang +sidebar_position: 2 +sidebar_class_name: gosdk +keywords: ['go', 'golang', 'sdk'] +description: Learn how to use the Golang SDK in this guide. +slug: /tools/sdk/go +tags: ['SDK', 'Software Development Kit'] +--- + +Read this guide to learn how to use the Go SDK. The Go SDK has some pre-built code examples you can use to learn how to build tools that can interact with IdentityNow. + +## Requirements + +You need the following to use the Go SDK: + +- Golang version 1.18 or above. You can download it [here](https://go.dev/dl/). You can use `go version` to check your version. + +- Your tenant name in IdentityNow. To learn how to find it, refer to [Getting Started](/idn/api/getting-started#find-your-tenant-name). The SDK will use this tenant name to connect to your IdentityNow instance. + +- A PAT with a client secret and ID. To learn how to create one in IDN, refer to [Personal Access Tokens](https://documentation.sailpoint.com/saas/help/common/api_keys.html#generating-a-personal-access-token). The SDK will use this PAT to authenticate with the SailPoint APIs. + + +## Setup + +
+CLI Assisted (Recommended) + +The SailPoint CLI offers a few commands that will allow you to quickly get started with the Go SDK. To learn how to install and use the SailPoint CLI, refer to [SailPoint CLI](https://developer.sailpoint.com/idn/tools/cli#get-the-cli). + +Once the CLI is installed and configured, run the following command to create a new Go project with our Go SDK. + +```bash +sail sdk init golang go-example +``` + +This will create the structure for your project. + +```text +|-- go-example +| |-- go.mod +| |-- go.sum +| |-- sdk.go +``` + +Navigate into your project folder and run the following command to install the required dependencies. + +```bash +go mod tidy +``` + +The SDK is now installed. To configure the SDK see [Configure](#configure). + + +
+ +
+Manual Installation + +To begin your go project, you will need to create a directory for your project. + +```bash +mkdir golang-example +``` + +Now change into your project directory: + +```bash +cd golang-example +``` + +Use the following command in your project directory. Doing so initializes your project and creates the `go.mod` file. You will edit this file to add the SailPoint SDK to your project. + +```go +go mod init github.com/github-repo-name/golang-example +``` + +Install the SailPoint SDK with the following command: + +```go +go get github.com/sailpoint-oss/golang-sdk +``` + +The SDK is now installed. To configure the SDK see [Configure](#configure). + +
+ +## Configure + +In order for the SDK to authenticate to your SailPoint tenant and make API calls you will need to provide configuration. This can be done through a configuration file `config.json` or through environment variables. + +### Configuration File + +The SDK requires a configuration file to be named `config.json` and provide the following key/value pairs `ClientID`, `ClientSecret`, `BaseUrl`. + +
+CLI Assisted (Recommended) +The SailPoint CLI offers a command to generate the config.json file with your currently configured CLI credentials. + +```bash +sail sdk init config +``` + +If you have multiple environments configured with the CLI you can pass an additional parameter to state the environment you wish to create a `config.json` for. + +```bash +sail sdk init config --env devrel +``` + +#### Example `config.json` + +```json +{ + "ClientID": "g0567b766b413b22c05c66e75d532f1b", + "ClientSecret": "cabd0e950a7230b63c1ff45be33fb22065b382b6251a73c61177a8bb5482fcc7", + "BaseUrl": "https://[tenant].api.identitynow.com" +} +``` + +
+ +
+Manual Configuration + +Create a file named `config.json` and provide `ClientID`, `ClientSecret`, `BaseUrl`. + +#### Example `config.json` + +```json +{ + "ClientID": "g0567b766b413b22c05c66e75d532f1b", + "ClientSecret": "cabd0e950a7230b63c1ff45be33fb22065b382b6251a73c61177a8bb5482fcc7", + "BaseUrl": "https://[tenant].api.identitynow.com" +} +``` + +
+ +### Environment variable configuration + +You can also store your configuration in environment variables. + +To get your environment variables to persist across terminal sessions, add these exports to your shell profile, something like `~/.bash_profile`. + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +```bash +export SAIL_BASE_URL=https://[tenant].api.identitynow.com +export SAIL_CLIENT_ID=[clientID] +export SAIL_CLIENT_SECRET=[clientSecret] +``` + + + + +```bash +$env:SAIL_BASE_URL=https://[tenant].api.identitynow.com +$env:SAIL_CLIENT_ID=[clientID] +$env:SAIL_CLIENT_SECRET=[clientSecret] +``` + +To get your environment variables to persist across PowerShell sessions, use these commands instead: + +```powershell +[System.Environment]::SetEnvironmentVariable('SAIL_BASE_URL','https://[tenant].api.identitynow.com') +[System.Environment]::SetEnvironmentVariable('SAIL_CLIENT_ID','[clientID]') +[System.Environment]::SetEnvironmentVariable('SAIL_CLIENT_SECRET','[clientSecret]') +``` + + + + +## Getting started with the Go SDK + +Once your SDK is installed and configured, you can start accessing the SDK's different functionalities. We will go through these now with some examples. + + +### List Transforms + +Create a file in your project called `sdk.go` with the following contents. + +```go +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) + + resp, r, err := apiClient.V3.TransformsApi.ListTransforms(ctx).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) + } + fmt.Fprintf(os.Stdout, "All Transforms from `TransformsApi.ListTransforms`: %v\n", resp) + +} +``` + +To run the code run the following command: + +```go +go run sdk.go +``` + +### 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). + +Pagination is implemented with the SDK in the following code block on line 18. + +```go showLineNumbers +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 `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) +} +``` + +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, the `Paginate` function is available to you. + +```go +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 `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) +} +``` + +The `Paginate` function must be provided the return type `v3.Account`, the list endpoint `ListAccounts`, initial offset `0`, increment `250`, and limit `150000`. + +### Search + +The Go SDK provides you access to IdentityNow's [Search](https://documentation.sailpoint.com/saas/help/search/index.html) functionality. + +Here is an example search you can copy into your Go code to try it out: + +```go +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) + + search := v3.NewSearchWithDefaults() + search.Indices = append(search.Indices, "identities") + searchString := []byte(` + { + "indices": [ + "identities" + ], + "query": { + "query": "*" + }, + "sort": [ + "-name" + ] + } + `) + search.UnmarshalJSON(searchString) + resp, r, err := apiClient.V3.SearchApi.SearchPost(ctx).Search(*search).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SearchPost``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `search` + for i := 0; i < len(resp); i++ { + fmt.Println(resp[i]["name"]) + } +} +``` + +### Paginate Search Results + +```go +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) + + search := v3.NewSearchWithDefaults() + search.Indices = append(search.Indices, "identities") + searchString := []byte(` + { + "indices": [ + "identities" + ], + "query": { + "query": "*" + }, + "sort": [ + "-name" + ] + } + `) + 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, "Full HTTP response: %v\n", r) + } + // response from `search` + for i := 0; i < len(resp); i++ { + fmt.Println(resp[i]["name"]) + } +} +``` + +### Retries + +## 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 diff --git a/products/idn/tools/sdk/powershell.md b/products/idn/tools/sdk/powershell.md.old similarity index 99% rename from products/idn/tools/sdk/powershell.md rename to products/idn/tools/sdk/powershell.md.old index 10d0e82c51f..a1c3fca2796 100644 --- a/products/idn/tools/sdk/powershell.md +++ b/products/idn/tools/sdk/powershell.md.old @@ -1,4 +1,4 @@ ---- + Read this guide to learn how to use the PowerShell SDK. The PowerShell SDK has some pre-built code examples you can use to learn how to build tools that can interact with IdentityNow. diff --git a/products/idn/tools/sdk/powershell.mdx b/products/idn/tools/sdk/powershell.mdx new file mode 100644 index 00000000000..26479910b0a --- /dev/null +++ b/products/idn/tools/sdk/powershell.mdx @@ -0,0 +1,424 @@ +--- +id: powershell-sdk +title: PowerShell SDK +pagination_label: PowerShell SDK +sidebar_label: PowerShell +sidebar_position: 3 +sidebar_class_name: powershellsdk +keywords: ['powershell', 'sdk'] +description: Learn how to use the PowerShell SDK in this guide. +slug: /tools/sdk/powershell +tags: ['SDK'] +--- + +Read this guide to learn how to use the PowerShell SDK. The PowerShell SDK has some pre-built code examples you can use to learn how to build tools that can interact with IdentityNow. + +## Requirements + +You need the following to use the PowerShell SDK: + +- PowerShell 6.2 or greater. To learn how to install, refer to [Installing PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.4). + +- Your tenant name in IdentityNow. To learn how to find it, refer to [Getting Started](/idn/api/getting-started#find-your-tenant-name). The SDK will use this tenant name to connect to your IdentityNow instance. + +- A PAT with a client secret and ID. To learn how to create one in IDN, refer to [Personal Access Tokens](https://documentation.sailpoint.com/saas/help/common/api_keys.html#generating-a-personal-access-token). The SDK will use this PAT to authenticate with the SailPoint APIs. + +## Setup + +
+CLI Assisted (Recommended) + +The SailPoint CLI offers a few commands that will allow you to quickly get started with the PowerShell SDK. To learn how to install and use the SailPoint CLI, refer to [SailPoint CLI](https://developer.sailpoint.com/idn/tools/cli#get-the-cli). + +Once the CLI is installed and configured, run the following command to create a new PowerShell project with our PowerShell SDK. + +```bash +sail sdk init powershell +``` + +This will create the structure for your project. + +```text +|-- powershell-template +| |-- paginate.ps1 +| |-- paginateAccounts.ps1 +| |-- patchEntitlement.ps1 +| |-- sdk.ps1 +| |-- search.ps1 +| |-- transform.ps1 +``` + +Run the following command to install the required dependencies. + +```powershell +Install-Module -Name PSSailpoint +``` + +This command installs the SailPoint PowerShell SDK module. You will be prompted to confirm that you are sure you want to install the module from 'PSGallery'. Enter "A" to say "Yes to All". + +If you already have a version of the PowerShell SDK installed, you can install a new version side-by-side with it by adding the `-Force` parameter to the end of your `Install-Module` commmand: + +```powershell +Install-Module -Name PSSailpoint -Force +``` + +To validate the module is installed, run `Get-Module -ListAvailable PSSailpoint` and verify that the module is listed. Additionally, you can run `Get-Command -Module PSSailpoint` to see the available commands included in the module. + +The SDK is now installed. To configure the SDK see [Configure](#configure). + +
+ +
+ Manual Installation + +### Manually Install the SDK + +If access to the PowerShell Gallery isn't available, you can also install the PowerShell SDK manually. Follow these steps to do so: + +:::caution + +If you manually install the module on a machine without access to the PowerShell Gallery, you will also need to manually install updates to the SDK. + +::: + +To manually install the PowerShell module: + +1. Download the source code zip from the most recent release on [GitHub](https://github.com/sailpoint-oss/powershell-sdk/releases) +2. Open the ZIP file, then open then folder labeled `powershell-sdk-x.x.x` with the `x.x.x` representing the version you downloaded +3. Extract the `PSSailpoint` module folder inside to one of the following locations: + - To install for the Current user: `C:\Users\\Documents\WindowsPowerShell\Modules\PSSailpoint` + - To install for All users (requires Administrator privileges): `C:\Program Files\WindowsPowerShell\Modules\PSSailpoint` +4. Run `Import-Module PSSailpoint` to import the module into the current session. +5. To validate the module is installed, run `Get-Module -ListAvailable PSSailpoint` and verify that the module is listed. Additionally, you can run `Get-Command -Module PSSailpoint` to see the available commands included in the module. + +The SDK is now installed. To configure the SDK see [Configure](#configure). + +
+ + +## Configure + +In order for the SDK to authenticate to your SailPoint tenant and make API calls you will need to provide configuration. This can be done through a configuration file `config.json` or through environment variables. + +### Configuration File + +The SDK requires a configuration file to be named `config.json` and provide the following key/value pairs `ClientID`, `ClientSecret`, `BaseUrl`. + +
+CLI Assisted (Recommended) +The SailPoint CLI offers a command to generate the config.json file with your currently configured CLI credentials. + +```bash +sail sdk init config +``` + +If you have multiple environments configured with the CLI you can pass an additional parameter to state the environment you wish to create a `config.json` for. + +```bash +sail sdk init config --env devrel +``` + +#### Example `config.json` + +```json +{ + "ClientID": "g0567b766b413b22c05c66e75d532f1b", + "ClientSecret": "cabd0e950a7230b63c1ff45be33fb22065b382b6251a73c61177a8bb5482fcc7", + "BaseUrl": "https://[tenant].api.identitynow.com" +} +``` + +
+ +
+Manual Configuration + +Create a file named `config.json` and provide `ClientID`, `ClientSecret`, `BaseUrl`. + +#### Example `config.json` + +```json +{ + "ClientID": "g0567b766b413b22c05c66e75d532f1b", + "ClientSecret": "cabd0e950a7230b63c1ff45be33fb22065b382b6251a73c61177a8bb5482fcc7", + "BaseUrl": "https://[tenant].api.identitynow.com" +} +``` + +
+ +### Environment variable configuration + +You can also store your configuration in environment variables. + +To get your environment variables to persist across terminal sessions, add these exports to your shell profile, something like `~/.bash_profile`. + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +```bash +export SAIL_BASE_URL=https://[tenant].api.identitynow.com +export SAIL_CLIENT_ID=[clientID] +export SAIL_CLIENT_SECRET=[clientSecret] +``` + + + + +```bash +$env:SAIL_BASE_URL=https://[tenant].api.identitynow.com +$env:SAIL_CLIENT_ID=[clientID] +$env:SAIL_CLIENT_SECRET=[clientSecret] +``` + +To get your environment variables to persist across PowerShell sessions, use these commands instead: + +```powershell +[System.Environment]::SetEnvironmentVariable('SAIL_BASE_URL','https://[tenant].api.identitynow.com') +[System.Environment]::SetEnvironmentVariable('SAIL_CLIENT_ID','[clientID]') +[System.Environment]::SetEnvironmentVariable('SAIL_CLIENT_SECRET','[clientSecret]') +``` + + + + +## Getting started with the PowerShell SDK + +To get an idea of what cmdlets the SDK offers run the following command. This lists all available Get cmdlets within the SDK. + +```powershell +Get-Command -Module PSSailpoint | where-object {$_.name -like "*Get-*" } | Sort-Object Name | Get-Help | Format-Table Name, Synopsis +``` + +The following output is returned + +```powershell +Name Synopsis +---- -------- +Get-AccessProfile Get an Access Profile +Get-AccessProfileEntitlements List Access Profile's Entitlements +Get-AccessProfiles List Access Profiles +Get-AccessRequestApprovalSummary Get the number of access-requests-approvals +Get-AccessRequestConfig Get Access Request Configuration +Get-AccessRequestStatus Access Request Status +Get-Account Account Details +Get-AccountActivities List Account Activities +Get-AccountActivity Get an Account Activity +Get-AccountEntitlements Account Entitlements +Get-Accounts Accounts List +Get-AccountsSchema Downloads source accounts schema template +Get-ActiveCampaigns List Campaigns +... +``` + +### List Transforms + +Let's say that you wanted to see all the transforms available in your tenant. You can search for the cmdlet like so. + +```powershell +Get-Command -Module PSSailpoint | where-object {$_.name -like "Get-*Transform*" } | Sort-Object Name | Get-Help | Format-Table Name, Synopsis +``` + +The following output is returned. All beta endpoints will be designated by the Beta prefix. + +```powershell +Name Synopsis +---- -------- +Get-BetaTransform Transform by ID +Get-BetaTransforms List transforms +Get-Transform Transform by ID +Get-Transforms List transforms +``` + +To get syntax, description and parameters for a single cmdlet, run the following command. + +```powershell +Get-Help Get-Transforms -Detailed +``` + +
+Cmdlet Response + + +```text +NAME + Get-Transforms + +SYNOPSIS + List transforms + + +SYNTAX + Get-Transforms [[-Offset] ] [[-Limit] ] [[-Count] ] [[-Name] ] [[-Filters] ] [-WithHttpInfo] [] + + +DESCRIPTION + Gets a list of all saved transform objects. A token with transforms-list read authority is required to call this API. + + +PARAMETERS + -Offset + Offset into the full result set. Usually specified with *limit* to paginate through the results. See [V3 API Standard Collection + Parameters](https://developer.sailpoint.com/idn/api/standard-collection-parameters) for more information. + + -Limit + Max number of results to return. See [V3 API Standard Collection Parameters](https://developer.sailpoint.com/idn/api/standard-collection-parameters) for more information. + + -Count + If *true* it will populate the *X-Total-Count* response header with the number of results that would be returned if *limit* and *offset* were ignored. Since requesting a total count can have a + performance impact, it is recommended not to send **count=true** if that value will not be used. See [V3 API Standard Collection + Parameters](https://developer.sailpoint.com/idn/api/standard-collection-parameters) for more information. + + -Name + Name of the transform to retrieve from the list. + + -Filters + Filter results using the standard syntax described in [V3 API Standard Collection Parameters](https://developer.sailpoint.com/idn/api/standard-collection-parameters#filtering-results) Filtering is + supported for the following fields and operators: **internal**: *eq* **name**: *eq, sw* + + -WithHttpInfo [] + A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response + + + This cmdlet supports the common parameters: Verbose, Debug, + ErrorAction, ErrorVariable, WarningAction, WarningVariable, + OutBuffer, PipelineVariable, and OutVariable. For more information, see + about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). +``` +
+ +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 name starts with `Test` + +### 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). + +Pagination is implemented with the SDK in the following code block on line 8. + +```powershell showLineNumbers +$Parameters = @{ + "Filters" = 'name co "Andrew"' +} + +# Accounts List +try { + + Invoke-Paginate -Function "Get-Accounts" -Increment 250 -Limit 1000 -InitialOffset 0 -Parameters $Parameters + +} catch { + Write-Host $_ + Write-Host ("Exception occurred when calling {1}: {0}" -f ($_.ErrorDetails | ConvertFrom-Json), "Get-Accounts") + Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json)) +} +``` + + +The `Invoke-Paginate` cmdlet takes a few paramters, the first is the cmdlet you wish to call. + +The `-Function` specifies the name of the cmdlet you wish to call. This only works on list endpoints. + +The `-Increment` specifies the number of results returned in each call to the endpoint. Defaults to 250. + +The `-Limit` specifies the total number of results you can return, 1000. + +The `-Parameters` specifies a hashtable of additional values passed to the API endpoint. You would use this for `filters`, `sorters` and any other query parameters. + +You can also provide an `-InitialOffset` value to specify the record number to start the request on. For example, you can provide add `-InitialOffset 10` to start getting accounts from 11 instead of 0. + +To find out whether an endpoint supports pagination, refer to its documentation. Any API supporting pagination lists the optional query parameters detailed in [Paginating Results](/idn/api/standard-collection-parameters/#paginating-results). + +### Search + +The PowerShell SDK provides you access to IdentityNow's [Search](https://documentation.sailpoint.com/saas/help/search/index.html) functionality. + +Here is an example search you can copy into your PowerShell instance to try it out: + +```PowerShell +$Json = @" +{ + "indices": [ + "identities" + ], + "query": { + "query": "\"john.doe\"", + "fields": [ + "name" + ] + } + } +"@ + +$Search = ConvertFrom-JsonToSearch -Json $Json + +try { + Search-Post -Search $Search +} catch { + Write-Host ("Exception occurred when calling Search-Post: {0}" -f ($_.ErrorDetails | ConvertFrom-Json)) + Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json)) +} +``` + +This example request uses the [Perform Search endpoint](/idn/api/v3/search-post) to search your tenant for identities with the name "john.doe". + +### Paginate search results + +You can paginate your search results to get records past the default limit of 10000. With pagination, you can get as many records as you want. + +Use the syntax shown in this example to paginate your search results: + +```powershell +$JSON = @" +{ + "indices": [ + "identities" + ], + "query": { + "query": "*", + "fields": [ + "name" + ] + }, + "sort": [ + "-displayName" + ] + } +"@ + +$Search = ConvertFrom-JsonToSearch -Json $JSON + +try { + + Invoke-PaginateSearch -Increment 5000 -Limit 150000 -Search $Search + +} catch { + Write-Host $_ + Write-Host ("Exception occurred when calling {1}: {0}" -f ($_.ErrorDetails | ConvertFrom-Json), "Paginate-Search") + Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json)) +} +``` + +This example searches your IdentityNow tenant for all identities and sorts them by their `displayName` in descending order. The search returns a maximum of 150000 records, the `Limit`, and 5000 records per page, the `Increment`. + +To paginate the search results, you can specify these parameters: -`Increment`: The number of records to return per page. -`Limit`: The maximum number of records to return per request. The default is 10000. -`Offset`: The number of the first record to return with the request. The default is 0. + +### Retries + +The SDK supports retry logic in the case of an unexpected error. The two configuration options you have available are as follows: + +* MaximumRetryCount - How many times to retry the request. Default is 10 retries. +* RetryIntervalSeconds - How many seconds to wait between retries. Default is 5 seconds. + +The following code will tell the SDK to retry 2 times after an unexpected error. It will wait 3 seconds in between retries. + +```powershell +Set-DefaultConfiguration -MaximumRetryCount 2 -RetryIntervalSeconds 3 +``` + +## 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 diff --git a/products/idn/tools/sdk/typescript.md b/products/idn/tools/sdk/typescript.md.old similarity index 99% rename from products/idn/tools/sdk/typescript.md rename to products/idn/tools/sdk/typescript.md.old index 7d14ddf6080..ef2c193fbb4 100644 --- a/products/idn/tools/sdk/typescript.md +++ b/products/idn/tools/sdk/typescript.md.old @@ -272,7 +272,7 @@ You can also provide an `initialOffset` value to specify the record number to st To find out whether an endpoint supports pagination, refer to its documentation. Any API supporting pagination lists the optional query parameters detailed in [Paginating Results](/idn/api/standard-collection-parameters/#paginating-results). -### Search +### Search To try using the IDN [search functionality](/idn/api/v3/search-post) along with pagination, copy this code into your "index.ts" file: diff --git a/products/idn/tools/sdk/typescript.mdx b/products/idn/tools/sdk/typescript.mdx new file mode 100644 index 00000000000..e8a4e9f4525 --- /dev/null +++ b/products/idn/tools/sdk/typescript.mdx @@ -0,0 +1,369 @@ +--- +id: typescript-sdk +title: TypeScript SDK +pagination_label: TypeScript SDK +sidebar_label: TypeScript +sidebar_position: 4 +sidebar_class_name: typescriptsdk +keywords: ['tsc', 'typescript', 'sdk'] +description: Learn how to use the TypeScript SDK in this guide. +slug: /tools/sdk/typescript +tags: ['SDK'] +--- + +## Overview + +Learn how to use the TypeScript SDK in this guide. The TypeScript SDK has some pre-built code examples you can use to learn how to build tools that can interact with IdentityNow (IDN). + +## Requirements + +You need the following to use the TypeScript SDK: + +- **Node**. To learn how to download it and set it up, go [here](https://nodejs.org/en/download). + +- **TypeScript**. You can use `npm` to install TypeScript globally, this means that you can use the `tsc` command anywhere in your terminal. To do this, run + +```bash +npm install -g typescript +``` + +- Your tenant name in IDN. To learn how to find it, refer to [Getting Started](/idn/api/getting-started#find-your-tenant-name). The SDK will use this tenant name to connect to your IDN instance. + +- A PAT with a client secret and ID. To learn how to create one in IDN, refer to [Personal Access Tokens](https://documentation.sailpoint.com/saas/help/common/api_keys.html#generating-a-personal-access-token). The SDK will use this PAT to authenticate with the SailPoint APIs. + +## Setup + +
+CLI Assisted (Recommended) + +The SailPoint CLI offers a few commands that will allow you to quickly get started with the Typescript SDK. To learn how to install and use the SailPoint CLI, refer to [SailPoint CLI](https://developer.sailpoint.com/idn/tools/cli#get-the-cli). + +Once the CLI is installed and configured, run the following command to create a new Typescript project with our Typescript SDK. + +```bash +sail sdk init typescript typescript-example +``` + +This will create the structure for your project. + +```text +|-- typescript-example +| |-- package.json +| |-- src +| | |-- index.ts +| |-- tsconfig.json +``` + +Navigate into your project folder and run the following command to install the required dependencies. + +```bash +npm install +``` + +The SDK is now installed. To configure the SDK see [Configure](#configure). + +
+ +
+Manual Installation + +To begin your typescript project, you will need to create a directory for your project: + +```bash +mkdir typescript-example +``` + +Now change into your project directory: + +```bash +cd typescript-example +``` + +Use the following command in your project directory. Doing so initializes your project and creates the `package.json` file. You will update this file with the dependencies necessary to use the SDK. + +```bash +npm init +``` + +Create a source folder named `src`. The SDK will include the `"src/**/*"` folder path when it compiles, so your SDK file must be there. + +```bash +mkdir src +``` + +Go to the `src` folder and create a file named `index.ts` in there. You will need to compile the `index.ts` file to run the SDK. You can leave this `index.ts` file empty for now. + +Go to the project directory and create a file named `tsconfig.json` in there. This file will contain your compiler configuration. Copy this information into your `tsconfig.json` file: + +```typescript +{ + "compilerOptions": { + "target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "module": "commonjs", /* Specify what module code is generated. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "esModuleInterop": true, /* Omit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + "strict": true, /* Enable all strict type-checking options. */ + "skipLibCheck": true, + "outDir": "./build", + "rootDir": "src", + "sourceMap": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules"] + } +``` + +Use the following command to add the SailPoint SDK to your project's dependencies: + +```bash +npm install sailpoint-api-client +``` + +or + +```bash +yarn add sailpoint-api-client +``` + +The SDK is now installed. To configure the SDK see [Configure](#configure). + +
+ +## Configure + +In order for the SDK to authenticate to your SailPoint tenant and make API calls you will need to provide configuration. This can be done through a configuration file `config.json` or through environment variables. + +### Configuration File + +The SDK requires a configuration file to be named `config.json` and provide the following key/value pairs `ClientID`, `ClientSecret`, `BaseUrl`. + +
+CLI Assisted (Recommended) +The SailPoint CLI offers a command to generate the config.json file with your currently configured CLI credentials. + +```bash +sail sdk init config +``` + +If you have multiple environments configured with the CLI you can pass an additional parameter to state the environment you wish to create a `config.json` for. + +```bash +sail sdk init config --env devrel +``` + +#### Example `config.json` + +```json +{ + "ClientID": "g0567b766b413b22c05c66e75d532f1b", + "ClientSecret": "cabd0e950a7230b63c1ff45be33fb22065b382b6251a73c61177a8bb5482fcc7", + "BaseUrl": "https://[tenant].api.identitynow.com" +} +``` + +
+ +
+Manual Configuration + +Create a file named `config.json` and provide `ClientID`, `ClientSecret`, `BaseUrl`. + +#### Example `config.json` + +```json +{ + "ClientID": "g0567b766b413b22c05c66e75d532f1b", + "ClientSecret": "cabd0e950a7230b63c1ff45be33fb22065b382b6251a73c61177a8bb5482fcc7", + "BaseUrl": "https://[tenant].api.identitynow.com" +} +``` + +
+ +### Environment variable configuration + +You can also store your configuration in environment variables. + +To get your environment variables to persist across terminal sessions, add these exports to your shell profile, something like `~/.bash_profile`. + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +```bash +export SAIL_BASE_URL=https://[tenant].api.identitynow.com +export SAIL_CLIENT_ID=[clientID] +export SAIL_CLIENT_SECRET=[clientSecret] +``` + + + + +```bash +$env:SAIL_BASE_URL=https://[tenant].api.identitynow.com +$env:SAIL_CLIENT_ID=[clientID] +$env:SAIL_CLIENT_SECRET=[clientSecret] +``` + +To get your environment variables to persist across PowerShell sessions, use these commands instead: + +```powershell +[System.Environment]::SetEnvironmentVariable('SAIL_BASE_URL','https://[tenant].api.identitynow.com') +[System.Environment]::SetEnvironmentVariable('SAIL_CLIENT_ID','[clientID]') +[System.Environment]::SetEnvironmentVariable('SAIL_CLIENT_SECRET','[clientSecret]') +``` + + + + +## Getting started with the Typescript SDK + +Once your SDK is installed and configured, you can start accessing the SDK's different functionalities. We will go through these now with some examples. + +To make sure that your SDK is connecting to the APIs you need, you can specify the API within the curly brackets in `import {}` at the top of the "index.ts" file. In this example, you could add `Configuration` and `TransformsApi` to add the functionality to list Transforms. + +### List Transforms in your tenant + +```typescript +import {Configuration, TransformsApi} from "sailpoint-api-client" + +const getTransforms = async() => { + // Initialize configuration, this requests a token using your configured credentials + // to be able to call out to APIs + let apiConfig = new Configuration() + + // Initialize the TransformsApi, this creates an instance of the TransformsApi. + // The configuration object is passed in so that the API can add your token to the request + let api = new TransformsApi(apiConfig) + + // Call out to your tenant to get the list of transforms. + let transforms = await api.listTransforms() + console.log(transforms) +} + +getTransforms() +``` + +To compile the file, first run the `tsc src/index.ts` command. This command creates a corresponding `index.js` file you can use to run the SDK. + +To run the SDK, run the `node src/index.js` command. This command sends the request and outputs a list of transforms stored in your tenant. + + +### List Transforms in your tenant filtering by query parameters + +Using the same SDK function, you can list your transforms but limit the results to only what you want. In this example we want a list of no more than 10 transforms that start with the name "Test". + +See [List Transforms](https://developer.sailpoint.com/idn/api/v3/list-transforms) for all its supported query parameters. + +```typescript +import {Configuration, TransformsApi} from "sailpoint-api-client" + +const getTransforms = async() => { + let apiConfig = new Configuration() + let api = new TransformsApi(apiConfig) + let transforms = await api.listTransforms({limit: 10, filters: 'name sw "Test"'}) + console.log(transforms) +} + +getTransforms() +``` + +To compile, run `tsc src/index.ts` and to run the code `node src/index.js`. + +### 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). + +Pagination is implemented with the SDK in the following code block on line 7. + +```typescript showLineNumbers +import {Configuration, AccountsApi, Paginator} from "sailpoint-api-client" + +const getPaginatedAccounts = async () => { + let apiConfig = new Configuration() + let api = new AccountsApi(apiConfig) + + const val = await Paginator.paginate(api, api.listAccounts, {limit: 1000}, 250) + + console.log(val) +} + +getPaginatedAccounts() +``` + +The function takes a few paramters, the first is the api instance that you wish to call, created on line 5. The next parameter is the function in which you want to invoke the pagination against. In the example above we want to list accounts so we call `api.listAccounts`. + +The `limit` specifies the total number of results you can return, 1000. The following unlabeled number, 250, refers to the `increment`, the number of records per page. For example, changing the `limit` to 50 and the following "250" to 5 would change the request to return a total of 50 records, 5 at a time. + +You can also provide an `offset` value to specify the record number to start the request on. For example, you can provide add `{offset: 11}` to start getting accounts from 11 instead of 0. + +To find out whether an endpoint supports pagination, refer to its documentation. Any API supporting pagination lists the optional query parameters detailed in [Paginating Results](/idn/api/standard-collection-parameters/#paginating-results). + + +### Search + +To try using the IDN [search functionality](/idn/api/v3/search-post) along with pagination, copy this code into your "index.ts" file: + +```typescript +const search = async () => { + let apiConfig = new Configuration() + let api = new SearchApi(apiConfig) + let search: Search = { + indices: [ + "identities" + ], + query: { + query: "*" + }, + sort: ["-name"] + } + const val = await Paginator.paginateSearchApi(api, search, 100, 1000) + + for (const result of val.data) { + const castedResult: IdentityDocument = result + console.log(castedResult.name) + } + +} +``` +This example returns 1000 identities, 100 at a time, and sorts them in descending order by name. You can also change the search pagination by changing "100" and "1000", respectively. + +The two main ways you can manipulate this example are to change the `indices` or the `query`. If you add `"access profiles"` to the indices, and the SDK will search access profiles too. If you change the query to "a*", the search will return all records starting with the letter "a". + +You can also change the sorting logic in the brackets next to `sort`. + +### Retries + +The SDK supports retry logic in the case of an unexpected error. See lines 7-12, you are able to configure the number of retries and the delay between retries. + +```typescript showLineNumbers +import {Configuration, axiosRetry, AccountsApi, Paginator} from "sailpoint-api-client" + +const getPaginatedAccounts = async () => { + + + let apiConfig = new Configuration() + apiConfig.retriesConfig = { + retries: 4, + retryDelay: axiosRetry.exponentialDelay, + onRetry(retryCount, error, requestConfig) { + console.log(`retrying due to request error, try number ${retryCount}`) + }, + } + let api = new AccountsApi(apiConfig) + + const val = await Paginator.paginate(api, api.listAccounts, {limit: 100}, 10) + + console.log(val) + +} + +getPaginatedAccounts() +``` + +## 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