---
updatedAt: 2025-08-14T13:32:59.000Z
agentTools:
  siteIndex: https://developer.n-able.com/llms.txt
  projectIndex: https://developer.n-able.com/n-central/llms.txt
---

# Create N-central API Access Token

```powershell PowerShell
$apiUrl = "https://Your N-central URL"
$JWT = "Your Json Web Token"

function NCentral-Authenticate {
    param (
        [string]$apiUrl,
        [string]$jwt
    )

    # Build the URI for the API endpoint
    $uri = "$apiUrl/api/auth/authenticate"

    # Build the Authorization header
    $headers = @{
        "Authorization" = "Bearer $jwt"
    }

    # Send the POST request to authenticate and obtain tokens
    $response = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers

    # Extract and return the tokens
    $tokens = $response.tokens
    $refreshEndpoint = $response.refresh
    $validateEndpoint = $response.validate

    return @{
        "AccessToken" = @{
            "Token" = $tokens.access.token
            "Type" = $tokens.access.type
            "ExpirySeconds" = $tokens.access.expirySeconds
        }
        "RefreshToken" = @{
            "Token" = $tokens.refresh.token
            "Type" = $tokens.refresh.type
            "ExpirySeconds" = $tokens.refresh.expirySeconds
        }
    }
}

$tokens = NCentral-Authenticate -apiUrl $apiUrl -jwt $JWT
$accessToken = $tokens.AccessToken.Token
```

```json Response Example
{"success":true}
```

# Set up the Variables

<!-- powershell@1-2 -->

Define and populate the API URL and the JSON Web Token (JWT) variables that will be used for authentication.

**$apiUrl**: The base URL for the API.
**$jwt**: The JSON Web Token for authentication.

# Define the NCentral-Authenticate Function

<!-- powershell@4-9 -->

The NCentral-Authenticate function handles the API authentication process and takes two parameters. The previously define **$apiUrl** and **$jwt**.

# Build the URI and Headers

<!-- powershell@10-16 -->

Build the full URI (Uniform Resource Identifier) for the API endpoint and prepare the necessary headers for the request. The term “Bearer” indicates that the token is a bearer token, meaning it grants access to resources without needing additional credentials.

# Send the POST request

<!-- powershell@18-19 -->

Invoke-RestMethod: This cmdlet sends a POST request to the specified URI with the provided headers. The response from the API is stored in the **$response** variable. This response typically includes tokens and other relevant data.

# Extract Tokens from the Response

<!-- powershell@21-25 -->

After sending the authentication request, the API responds with a set of tokens. In this step, we extract these tokens from the response object.
**$tokens**: This variable captures the tokens from the API response.
**$refreshEndpoint** and **$validateEndpoint**: These variables extract additional endpoints for refreshing and validating tokens.

# Returning the Tokens

<!-- powershell@26-38 -->

The Authenticate function prepares and returns a structured set of tokens. The function returns a hashtable containing two nested hashtables: one for the access token and one for the refresh token.

# Call the Authenticate Function

<!-- powershell@40,41 -->

The Authenticate function constructs the full URI for the authentication endpoint, builds the necessary headers, sends a POST request, and processes the response to extract the token.