Query the Connect API Explorer from Powershell
Review examples on how to query the API using Windows PowerShell.
3 minute read
The examples in this topic illustrate how to query the API using Windows PowerShell.
Tip
The application SDK includes a toolkit with sample code and explanations of additional ways that you can interact with the Connect API Explorer using third-party applications. To get access to the UI Extension SDK, contact Discover.Sales@Nuix.com.Before you start
Before you start, do the following:
- Obtain your application API token. Your token authenticates you. For more information, see Obtain an API token.
Warning
Store your API token in a secure location, the same way that you protect your password. Anyone who has your token can access all of the data that you can access through the API. - Obtain the URL of the API service for the portal from your system administrator. The URL of the API service is available in the Portal Management area, in the Settings section, on the Portal Options page. For more information, see Connect API Explorer URL.
Sample PowerShell GET request
Use the following sample PowerShell GET request as a starting point to perform operations in PowerShell.
$uriPrefix = "URL of the API service for the portal?q="
$token = "Your API token"
$query = "{ users { userName } }"
$uri = $uriPrefix + [uri]::EscapeDataString($query)
$request = [System.Net.WebRequest]::Create($uri)
$request.Method = "GET"
$request.Headers["Authorization"] = "Bearer $token"
$result = $request.GetResponse()
$stream = $result.GetResponseStream()
$reader = New-Object IO.StreamReader($stream)
$reader.readToEnd()
In the request, provide values for the following elements:
- The URL of the API service for the portal, such as http://ringtail.com/Ringtail-Svc-Portal/api/query. Make sure that the URL is followed by ?q=. For more information, see Before you start.
- Your API token.
- The operation to run, formatted as valid JSON syntax. The sample request encodes the JSON query into valid syntax that can be passed as part of a URL.
For information about how to create and test queries in the Connect API Explorer before running queries in a third-party application, see Access and use the Connect API Explorer.
Sample PowerShell POST request
Use the following sample PowerShell POST request as a starting point to perform operations in PowerShell.
$uri = "URL of the API service for the portal"
$token = "Your API token"
$body = "{""query"":""{ users { userName }}""}"
$request = [System.Net.WebRequest]::Create($uri)
$request.ContentType = "application/json"
$request.Method = "POST"
$request.Headers["Authorization"] = "Bearer $token"
$stream = $request.GetRequestStream()
$stream.Write([byte[]][char[]]$body, 0, $body.Length)
$result = $request.GetResponse()
$stream = $result.GetResponseStream()
$reader = New-Object IO.StreamReader($stream)
$reader.readToEnd()
In the request, provide values for the following elements:
- The URL of the API service for the portal, such as http://ringtail.com/Ringtail-Svc-Portal/api/query. For more information, see Before you start.
- Your API token.
- The operation to run, formatted as valid JSON syntax. Use outer double quotation marks.
For information about how to create and test queries in the Connect API Explorer before running queries in a third-party application, see Access and use the Connect API Explorer.
Feedback
Was this page helpful?
Thank you for your feedback.
Thank you for your feedback.