What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

API requests - 404 error

Votes:

0

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.

api http-request prtg

Created on May 28, 2015 3:07:05 PM



7 Replies

Votes:

0

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?

Created on May 28, 2015 7:52:51 PM



Votes:

0

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.

Created on May 28, 2015 8:52:39 PM



Votes:

0

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.

Created on Jun 1, 2015 11:42:24 AM by  Stephan Linke [Paessler Support]

Last change on Jun 1, 2015 11:42:33 AM by  Stephan Linke [Paessler Support]



Votes:

0

[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

Created on Jun 2, 2015 9:58:18 PM

Last change on Jun 3, 2015 6:13:21 AM by  Stephan Linke [Paessler Support]



Votes:

0

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"

Created on Jun 3, 2015 7:04:02 AM by  Stephan Linke [Paessler Support]



Votes:

0

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.

Created on Jun 3, 2015 5:51:01 PM

Last change on Jun 4, 2015 8:32:02 AM by  Stephan Linke [Paessler Support]



Votes:

0

Okay, let me know if you need further help :)

Created on Jun 4, 2015 8:32:14 AM by  Stephan Linke [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.