I receive a '404' error when I make any API call. I am trying to learn how to make API requests. I know practically nothing about it, so I imagine I am doing several things wrong. I am using the HTTP API guide, provided in PRTG Setup.
I am using the following Powershell request, on the server that hosts the probe:
Invoke-WebRequest "http://myserver/api/getsensordetails.xml?id=5025&username=myuser&passhash=0987654321"
The user is an administrator. The server is within our LAN, although we access it via 'https'. If I make the request with https://... I receive a "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel" error.
Any help is appreciated. Cheers.
Article Comments
I am just running it from the PowerShell console. I am trying to figure out how it works. If I use HTTPS in the API call I receive the error regarding trust relationships.
May, 2015 - Permalink
Execute this beforehand:
# Ignore invalid SSL certs in a webrequest [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
The PowerShell instance will then ignore certificates that are invalid for some reason.
Jun, 2015 - Permalink
[13]: C:\ > [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} [14]: C:\ > Invoke-WebRequest "https://xxxxx/api/getsensordetails.xml?id=5025&username=myuser&passhash=0987654321" Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. At line:1 char:1 + Invoke-WebRequest "https://xxxxxx/api/getsensordetails.xml?id=5025&u ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Jun, 2015 - Permalink
Seems like my line isn't sufficient somehow. How about this one:
Add-Type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy $result = Invoke-WebRequest -Uri "https://IpAddress/resource"
Jun, 2015 - Permalink
I found that solution, as well. I tried it with similar results. Here is the fiddler trace:
Session #12: The remote server (myserver) presented a certificate that did not validate, due to RemoteCertificateNameMismatch, RemoteCertificateChainErrors. 0 - A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider. SUBJECT: CN=PRTG Demo Certificate, O=PRTG Demo Certificate ISSUER: CN=PRTG Demo Certificate, O=PRTG Demo Certificate EXPIRES: 7/6/2023 6:15:05 AM (This warning can be disabled by clicking Tools | Fiddler Options.)
I will work through the ssl certificate kb article, to try and resolve this.
Jun, 2015 - Permalink
If you use HTTPS to connect to your PRTG server, you must also use HTTPS in the API call.
How are you using the API call, is it in a VB or C# programm?
May, 2015 - Permalink