Skip to content

Commit 39966e7

Browse files
Merge pull request #286 from netwrix/changetracker/api-overview-fix
Add authentication example script
2 parents f4e374e + ee84c9f commit 39966e7

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: "Authentication"
3+
description: "Authentication"
4+
sidebar_position: 10
5+
---
6+
7+
# Authentication
8+
9+
The following PowerShell script is an example of how to authenticate to the ChangeTracker API.
10+
It prompts the user for the URL and credentials. It also asks wether to skip certificate validation or not and then creates a new session.
11+
Trusted certificates are recommended for all environments, but if you are using self-signed certificates in a lab environment, you have the option to skip certificate validation.
12+
13+
The variable ```$NctSession``` is used to store the session information and can be used to make subsequent API calls.
14+
15+
16+
```powershell
17+
$url = Read-Host "Enter URL (https://192.168.1.1/api)"
18+
19+
# Do not use this in production environments where trusted certificates are required
20+
$SkipCertificateCheck = Read-Host "Skip Certificate Check (y/n)"
21+
if ($SkipCertificateCheck -eq "y") {
22+
$SkipCertificateCheck = $true
23+
}
24+
else {
25+
$SkipCertificateCheck = $false
26+
}
27+
28+
# Collect credentials
29+
$username = Read-Host "Enter Username"
30+
$password = Read-Host "Enter Password" -AsSecureString
31+
$ApiCredential = New-Object System.Management.Automation.PSCredential ($username, $password)
32+
Remove-Variable -Name password
33+
34+
# Build request
35+
$body = @{
36+
"UserName" = $ApiCredential.UserName
37+
"Password" = $ApiCredential.GetNetworkCredential().Password
38+
"RememberMe" = "false"
39+
} | ConvertTo-Json
40+
41+
# Create new session
42+
$uri = "$($url)/auth/credentials"
43+
44+
$NctSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
45+
46+
try {
47+
Invoke-RestMethod `
48+
-Method Post `
49+
-ContentType application/json `
50+
-Uri $uri `
51+
-Headers @{ Accept = 'application/json' } `
52+
-Body $body `
53+
-WebSession $NctSession `
54+
-SkipCertificateCheck:$SkipCertificateCheck
55+
}
56+
catch {
57+
Write-Error "Failed to create session: $_"
58+
throw
59+
}
60+
finally {
61+
Remove-Variable -Name body
62+
}
63+
```

docs/changetracker/8.1/integration/api/overview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ Netwrix Change Tracker provides a comprehensive REST API that allows customers t
1010

1111
## Authentication
1212

13-
All API endpoints require authentication. You'll need to include appropriate authentication credentials with your requests. The specific authentication method is detailed in each API documentation page.
13+
All API endpoints require authentication. See [Authentication](/docs/changetracker/8.1/integration/api/authentication.md) for an example script.
1414

15-
## Available APIs
15+
## Available Endpoints
1616

1717
The following API endpoints are available in Netwrix Change Tracker:
1818

1919
- [Agents](/docs/changetracker/8.1/integration/api/agents.md) – Pull data on agent statuses, configurations, and group memberships using the agentsRanked endpoint. This API allows you to retrieve detailed information about all agents in your environment, including their group memberships and applied tracking templates.
2020

21-
- [Register Agents](/docs/changetracker/8.1/integration/api/register-agents.md)Register new agents with the system using the agents/register endpoint. This API allows you to register both direct agents installed on devices and proxied devices accessed through another agent.
21+
- [Register Agents](/docs/changetracker/8.1/integration/api/register-agents.md)Normally used by agents to register with the Hub, but this API allows you to register proxied devices to be accessed through a proxy agent.
2222

2323
- [Credentials](/docs/changetracker/8.1/integration/api/credentials.md) – Manage authentication credentials used by ChangeTracker to connect to various systems and services. This API provides endpoints for creating, retrieving, updating, and deleting credentials for different credential types including Shell, Database, FTP, Cloud, ESX, ITSM, and Splunk.
2424

0 commit comments

Comments
 (0)