I'm using cURL to do an api call but receive <HTML><BODY><B>Unauthorized</B></BODY></HTML> as a return. I've tried both password and passhash in the url but both get the same results. If I use the exact same url in my browser I get the xml output fine.
Why do I get unauthorized when calling the API?
Votes:
0
23 Replies
Votes:
0
Could you please post the URL in case? You could also forward us the same to [email protected]. In the latter case, please refer to this thread in your mail.
Votes:
0
The URL I'm using is https://"myserver:port"/api/table.xml?content=sensortree&username="myusername"&passhash="myhash" Of course everything in quotes has been replaced. I tried other content such as content=sensors&columns=sensors but they gave the same result.
Votes:
0
In this case it could really only be a wrong username or passhash. Just on the off chance, does it work with "?login=xxx&passhash=xxx'?
Votes:
0
It does not, I also tried name instead of username because I saw an example using that somewhere.
Votes:
0
I just tried with http://mysevrver/api/table.xml?content=sensortree&username=xxx&passhash=xxx and it worked just fine. Could this have to do with your username? Do you have any special characters or similar in the same?
Votes:
0
No special characters in the username or server address, there is an @ symbol in the password, but obviously not the hash. Are you doing this with cURL?
Created on Jan 30, 2014 2:41:56 PM
Last change on Jan 30, 2014 7:37:37 PM by
Patrick Hutter [Paessler Support]
(7,225)
●3
●3
Votes:
0
Could it be that cookies for a valid PRTG session still exist in the browser? If so, you wouldn't notice that it is logging in wrongly, seeing as you would receive the data of said session.
Votes:
0
No, cURL is a command-line based browser. I managed to get it working though. The proper method with cURL is to put the entire URL in quotes so that it doesn't try to extract the parameters and pass them seperately. Here is my working example: curl -k -o /home/username/PRTG/test.xml "https://server:port/api/table.xml?content=messages&output=csvtable&columns=objid,datetime,parent,type,name,status,message&username=myuser&password=mypass"
Votes:
0
Sorry for bringing this post back to the graveyard, but I have the same case. Exactly the same "Unauthorized" response also using cURL. I tried to work around using "user agents" to simulate conventional browsers like Chrome and Firefox but resultless. But when I use the same url in a conventional browser I works fine.
Can anyone help me?
Votes:
0
What URL are you using? Strip the actual passhash and username and I'll have a look.
Votes:
0
Hi! Patrick, I'm also facing the same problem. can't seems to get the cURL working on my Ubuntu terminal or script.
My Curl
curl http://172.16.17.5:8080/api/getobjectstatuscustom.htm?id=2218&name=lastvalue&show=text&content=lastvalue&username=xxxxx&passhash=yyyyy }}}} This is the response from the curl command at Ubuntu {{{ <HTML><BODY><B>Unauthorized</B></BODY></HTML>
However the same URL works perfectly on my browser The result I got at my browser was the temperature of my UPS
33 °C
Below is the actual page view source
<?xml version="1.0" encoding="UTF-8" ?> <prtg> <result>33 °C</result> </prtg>
May I know how can I resolve this problem?
Created on Jul 8, 2017 1:17:47 PM
Last change on Jul 10, 2017 4:59:25 AM by
Luciano Lingnau [Paessler]
Votes:
0
Hi Ivan,
Please put the URL in the command in double-quotes:
curl "http://172.16.17.5:8080/api/getobjectstatuscustom.htm?id=2218&name=lastvalue&show=text&content=lastvalue&username=xxxxx&passhash=yyyyy" |
Does that work better?
Best regards.
Votes:
0
I am having same issue, I was using Postman and curl to see what different results I could get. My query is to get a list of all the host that are in the database.
Using curl:
curl -k -o C:\Users\smiles\Desktop\prtghost.xml "http://"myprtgserver"/api/table.xml?content=devices&output=csvtable&columns=device,host?username="xxxx"&passhash="xxx" "
myprtgserver is an IP address and username and password I have verified
with postman I just select GET and enter the url string both give me the "unauthorized" tag on it.
<?xml version="1.0"?> -<HTML> -<BODY> <B>Unauthorized</B> </BODY> </HTML>
Not sure what I am missing.
Created on Feb 11, 2020 7:30:45 PM
Last change on Feb 12, 2020 12:32:36 PM by
Moritz Heller [Paessler Support]
Votes:
0
Hi smiles,
did you already tried the simple command:
curl "http://"myprtgserver"/api/table.xml?content=devices&output=csvtable&columns=device,host?username=xxxx&passhash=xxx
In addition, please use no double-quotes in username and passhash
Votes:
0
My output comes out to:
curl: (6) Could not resolve host: https
Which this is a new result from before.
Votes:
0
I found a mistake. Sorry about that.
I used the url you gave me....
and it gives me:
<HTML><BODY><B>Unauthorized</B></BODY></HTML>
Votes:
0
Hi smiles,
Thank you for the feedback.
This is only a dummy link. You need to replace "myprtgserver" with your Core Server URL and then replace the username and passhash according to the used credentials.
Votes:
0
I am aware of that.....I replaced it with my server and the username / hash with the correct information. The above result was still the result
Votes:
0
Hi smiles,
Thank you for the feedback.
Did you already tested the API call in an inkognito tab of your browser? In addition, I noticed that you have a "?" after "host". Please note that a "?" displays the start of parameters. However in this URL the parameters already started and therefore you would need to replace the "?" with a "&".
Votes:
0
When I replace the ? with the &:
I get:
<HTML>
<BODY><B>Unauthorized</B></BODY>
</HTML>
When I paste the URL into the incognito browser, I get:
Unauthorized
Votes:
0
Hi Smiles,
I noticed that you forgot a "=" after passhash. Did you used the same URL while testing? You can also create a API query via our "XML Table Query Builder" which is under "Setup > PRTG API > Live Data".
Votes:
0
The problem wasn't the string. It was the SSL certification check. If you turn that off or switch to turn this off, then the string as it was originally worked.
I did add the = at the end before the password.
Votes:
0
Hi smiles,
Thank you for the feedback. Glad to hear that the API call works now!
Add comment