How to use an API token

Authenticate and run GraphQL queries with API tokens in GraphQL client, or PowerShell.

GraphQL clients

When using tools like Apollo Explorer, Postman, or any other GraphQL client, you must include the API token in the request header:

Authorization: Bearer ENTER_YOUR_API_TOKEN

Info
Replace ENTER_YOUR_API_TOKEN with your API token

Review Auth in GraphOS Studio for more information on how to include headers in Apollo Explorer.

PowerShell

In this section, you'll learn how to authenticate and execute GraphQL queries using PowerShell and the PSGraphQL module.

PSGraphQL automatically handles the POST request, JSON conversion, and response parsing.

  1. Install the PSGraphQL module (if not already installed).

    Install-Module -Name PSGraphQL -Scope CurrentUser

  2. Import the module.

    Import-Module PSGraphQL

  3. Set the GraphQL endpoint and access token.

    $uri = "[https://api.n-able.com/graphql](https://api.n-able.com/graphql)"

    $accessToken = "ENTER_YOUR_API_TOKEN"

Info
Replace ENTER_YOUR_API_TOKEN with your API token

Define the GraphQL query.


$query = @" 
    query { 
     customers { 
       customerId 
       customerName 
       devices { 
         siteName 
         deviceId 
         longName 
         deviceClass 
      } 
     } 
   } 
"@ 

Set up headers for authentication.


$headers = @{ 
    "Authorization" = "Bearer $accessToken" 
} 

Execute the GraphQL query.

$response = Invoke-GraphQLQuery -Uri $uri -Query $query -Headers $headers


What’s Next

For further information on authentication and our API tokens visit: