Configure API for Instance Info

OS Name/Version: Windows Server 2019

Product Name/Version: AMP v2.5.0.10

Problem Description: Unable to successfully setup/utilize API to get instance info.
I have followed guidance to configure the AMPConfig.cong file to setup API key.


AMPConfig.conf modification

Security.APIKey=##################

# Add the required permissions for the API key
Security.APIKeyPermissions={
  "89e0b5c4-9cc4-467c-9637-07826a90a740": [
    "Session.Exists",
    "Core.GetStatus",
    "Core.Read",
    "Core.Write"
  ]
}

API Request

# Define headers and body
$headers = @{
    "Content-Type" = "application/json"
    "Accept"= "application/json"
    "Authorization" = "Bearer 89e0b5c4-9cc4-467c-9637-07826a90a740"
}

$body = @{
    "InstanceID" = "ff0498e6-1334-4d33-9a8f-babb1245d3bf"
} | ConvertTo-Json

# Invoke the API request
$response = Invoke-RestMethod -Uri "http://localhost:8081/API/Core/GetStatus" -Method Post -Headers $headers -Body $body

# Output the response
$response

This is the output I receive.

Title               Message                                                                                                                                         Stack
                                                                                                                                                                    Trace
-----               -------                                                                                                                                         -----
Unauthorized Access You do not have permission to use this method (GSMyAdmin.WebServer.GetStatus) at this time. This method requires the Session.Exists permission. ...

It seems the AMPConfig files would revert after starting the server, so I tried setting to read only still with no luck.

Steps to reproduce:

  • Step 1: Stop all running instances and ADS01
  • Step 2: Modify AMPConfig.conf to setup API
  • Step 3: Start instances and ADS01
  • Step 4: Files are overwritten by AMP on instance startup.
  • Step 5: Setting files to read only doesn’t seem to help.
  • Step 6: Consistent error
Title               Message                                                                                                                                         Stack
                                                                                                                                                                    Trace
-----               -------                                                                                                                                         -----
Unauthorized Access You do not have permission to use this method (GSMyAdmin.WebServer.GetStatus) at this time. This method requires the Session.Exists permission. ...

Actions taken to resolve so far:

  • Attempt to set config files read only to prevent overwrite
  • Utilize CURL and Postman to attempt API without success
  • Set explicit API permissions for Session.Exists to try to overcome permissions issue

AMP doesn’t use API keys as far as I know. You need to login via the API (API/Core/Login) to get a session ID first, then add that to the body as SESSIONID.
I got a bunch of notes in this repo here: https://github.com/p0t4t0sandwich/ampapi-spec
And a pin with more info in the development channel of the discord.
The Session.Exists error just means you didn’t authenticate correctly.

Note: Core/GetStatus also doesn’t take in any parameters, since you call it from the instance’s web endpoint (or proxy the API instance through the ADS)

1 Like

Hi there!
Thank you for the feedback.
This was a huge help!

I was able to utilize /API/Core/Login to get the session ID and GetStatus on the ADS01 instance that runs on port 8080 by default.


GetStatus Results

{
    "State": 999,
    "Uptime": "0:02:57:46",
    "Metrics": {
        "CPU Usage": {
            "RawValue": 0,
            "MaxValue": 100,
            "Percent": 0,
            "Units": "%",
            "Color": "#239B2D",
            "Color2": "#239B2D",
            "Color3": "#FFF"
        },
        "Memory Usage": {
            "RawValue": 0,
            "MaxValue": 16383,
            "Percent": 0,
            "Units": "MB",
            "Color": "#246BA0",
            "Color3": "#FFF"
        },
        "Active Users": {
            "RawValue": 0,
            "MaxValue": 0,
            "Percent": 0,
            "Units": "",
            "Color": "#7B249E",
            "Color3": "#FFF"
        }
    }
}

Would I need to query 8081 if that is for the Server Instance in particular I am wanting to report on?
I have a few instances running and 8080 only shows stats for what I assume is the primary ADS01 instance.

I tried modifying to get it to work with 8081, which is the port for the server instance I want to report uptime for, but the request times out.
I can access localhost:8081/api like I can with localhost:8080/api but it is not responding.

Thank you again for your assistance!

Yeah that sounds right. /API needs to be capitalized though

Hi,

Thank you again for the support!
I was able to get everything working as needed.

Really appreciate the quick responses!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.