Can anyone help me with a PS script.?

36 Views Asked by At

...it's connecting to the Emsisoft API (https://api.emsisoft.com/) to create a workspace, but I need help understanding the error.

# Define your API endpoint URL
$apiUrl = "https://api.emsisoft.com/v1/workspaces"

# Set your API key
$apiKey = "XXXXXXXXXXXXXXXXXXXXXXX"

# Create headers with API-KEY and ACCEPT
$headers = @{
    "API-KEY" = $apiKey
    "ACCEPT" = "application/json"
    "Content-Type" = "application/json"
}
$body = @{
        "name"="XXXXXXXXXXXXXXXXXXXXXXX"
        "securityManagementLevel"="LocalAndRemote"
        "licenseKey"="ABC-XXX-XXX-123"

}
# Make the API request
try {
    $response = Invoke-RestMethod -Uri $apiUrl -Headers $headers -Method Post -Body $body -ContentType 'application/json'

    # Process the response (e.g., parse JSON, handle data)
    # ...
    
    Write-Host "API request successful!"
} catch {
    Write-Host "Error: $_"
}

and the error

Error: {
  "error": {
    "code": "ValidationFailed",
    "message": "Unexpected character encountered while parsing value: s. Path '', line 0, position 0.",
    "target": ""
  }
}

Tried changing " to '.

1

There are 1 best solutions below

0
Re1ter On

From your link, I see that the request requires passing the following fields:

{
    "name": "My workspace",
    "preferableProduct": "EAM",
    "securityManagementLevel": "LocalAndRemote",
    "deviceCountToProtect": 5
}

However, you pass:

{
    "name"="XXXXXXXXXXXXXXXXXXXXXXX"
    "securityManagementLevel"="LocalAndRemote"
    "licenseKey"="ABC-XXX-XXX-123"
}