How-To (NGTS): Add or remove Workspaces from a Scope

How-To (NGTS): Add or remove Workspaces from a Scope

94
Created On 12/02/26 19:37 PM - Last Modified 12/02/26 21:59 PM


Objective


This article covers how to add or remove Workspaces from a Scope within NGTS.

 

You can view the existing Scope-to-Workspace assignment on the "System Settings > Certificate Settings > Workspaces" page.



Environment


NGTS



Procedure


  1. You must have a service account to acquire an access token. Refer to our official docs: https://pan.dev/scm/api/config/ngts/ngts-api/#authentication
  2. Paste the following script in PowerShell ISE and update the values in Step #0 to match your environment. This script will remove all Workspaces from the target Scope.
    1. ### Step 0 - Update these values to match your environment
      $tsg_id = <TSG-ID>
      $clientId = "<CLIENT-ID>"
      $clientSecret = "<CLIENT-SECRET>"
      $scope_name = "<SCOPE-NAME>"
      $scope_description = "<SCOPE-DESCRIPTION>" # Blank value will result in a blank description field
      
      
      ### Step 1 - Get access token
      $basicAuth = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("${clientId}:${clientSecret}"))
      $jwt = Invoke-RestMethod -Method Post `
        -Uri "https://auth.apps.paloaltonetworks.com/oauth2/access_token" `
        -Headers @{ Authorization = "Basic $basicAuth" } `
        -ContentType "application/x-www-form-urlencoded" `
        -Body "grant_type=client_credentials&scope=tsg_id:$tsg_id"
      $access_token = $jwt.access_token
      Write-Host "Token ending in $($access_token.Substring($access_token.Length - 10))" -ForegroundColor Green
      
      
      ### Step 2 - Get Scope info
      Invoke-RestMethod -Method Get `
        -Uri "https://api.strata.paloaltonetworks.com/iam/v1/scopes/$scope_name" `
        -Headers @{Authorization  = "Bearer $access_token"} `
        -OutVariable response2
      
      
      ### Step 3 - Update Scope info (Remove all workspaces from a Scope object)
      $body = @{description = $scope_description;resources = @()} | ConvertTo-Json -Depth 3
      Invoke-RestMethod -Method Put `
          -Uri "https://api.strata.paloaltonetworks.com/iam/v1/scopes/$scope_name" `
          -Headers @{Authorization = "Bearer $access_token"} `
          -Body $body `
          -OutVariable response3
  3. See example output of the script. The resources list should become blank if successful.
  4. You can add Workspaces to a Scope as follows:
    1. Add a single workspace:
      1. ### Update scope info (Add one workspace to a scope object)
        $body = @{
            description = $scope_description
            resources   = @(
                @{
                    resource_type = "ngts_workspace"
                    resource_id   = "1002"
                }
            )
        } | ConvertTo-Json -Depth 3
        
        $response = Invoke-RestMethod -Method Put `
            -Uri "https://api.strata.paloaltonetworks.com/iam/v1/scopes/$scope_name" `
            -Headers @{
                Authorization = "Bearer $access_token"
            } `
            -ContentType "application/json" `
            -Body $body
        $response
    2. Add multiple workspaces:
      1. ### Update scope info (Add multiple workspaces to a scope object)
        $body = @{
            description = $scope_description
            resources   = @(
                @{
                    resource_type = "ngts_workspace"
                    resource_id   = "1002"
                },
                @{
                    resource_type = "ngts_workspace"
                    resource_id   = "1003"
                }
            )
        } | ConvertTo-Json -Depth 3
        
        $response = Invoke-RestMethod -Method Put `
            -Uri "https://api.strata.paloaltonetworks.com/iam/v1/scopes/$scope_name" `
            -Headers @{
                Authorization = "Bearer $access_token"
            } `
            -ContentType "application/json" `
            -Body $body
        $response
  5. Get current Scope info:
    1. ### Step 2 - Get Scope info
      Invoke-RestMethod -Method Get `
        -Uri "https://api.strata.paloaltonetworks.com/iam/v1/scopes/$scope_name" `
        -Headers @{Authorization  = "Bearer $access_token"} `
        -OutVariable response2
  6. Process complete.


Additional Information


Modifying the Scope's assigned Workspaces is not currently an option in the UI, so it must be done via API.



Actions
  • Print
  • Copy Link

    https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA1hj0000001xqrCAA&lang=en_US&refURL=http%3A%2F%2Fknowledgebase.paloaltonetworks.com%2FKCSArticleDetail