0

I'm trying to pull some reports out a peace of software using HTML and JavaScript/jquery,

https://docs.x-formation.com/display/LICSTAT/Using+License+Statistics+API

here is the documentation for it however it just talks about using

curl -H "X-Auth-token: token" "https://yourdomain:888/url-to-api" 

which I don't understand from my goggling it appears to be a command line tool for getting data. but the documentation talks about using a web base API.

also if I tried doing the below

$.get(http://ExampleServer:1234/api/v1/report/license-server/1/current-usage/csv")

which brings back a 404 error page not found this is an example of the API to get current server licence usage that the documentation gives an example of but I just cant get anything back.

does anyone have any information they could help me with.

Kiran Joshi
  • 1,758
  • 2
  • 11
  • 34
adam Wadsworth
  • 774
  • 1
  • 8
  • 26
  • Docs will often show request structures using raw cURL requests (which is what that is). It's then up to you, the developer, to translate that request into the grammar (langhage) of your choice - in your case, JavaScript. You'lll need to pass a `X-Auth-token` header (that's what `-H` is) with the request. [Here's how](https://stackoverflow.com/questions/3258645/pass-request-headers-in-a-jquery-ajax-get-call) to pass headers in jQuery-wrapped AJAX requests. – Mitya Jul 02 '18 at 12:13
  • Thanks @Utkanos is the lack of header the reason I'm getting a 404 page not found error when I do the $.get request? – adam Wadsworth Jul 02 '18 at 12:16
  • Probably not, not sure about the whole url, looks like the 2 ports don't match, that would be a reason for getting the 404 – Mehdi Jul 02 '18 at 12:17
  • if it's a 404 - the page doesn't exist. The best way to test if it doesn't exist is to take the url paste it into a browser - see what it comes back with – treyBake Jul 02 '18 at 12:33
  • @ThisGuyHasTwoThumbs thanks I've done that and I still get nothing back but I'm putting the correct stuff into the url from the API documentation so I'm getting a bit stuck. – adam Wadsworth Jul 02 '18 at 12:46
  • @adamWadsworth - whether that's the cause of the 404 is something only the API designers will know. I wouldn't normally expect a 404 for a missing header; there are more suitable error codes. 404 suggests the URL structure is wrong. – Mitya Jul 02 '18 at 12:49
  • 1
    @Utkanos That would be my thoughts to. Thanks for your help – adam Wadsworth Jul 02 '18 at 12:51

1 Answers1

0

cURL is just one way of consuming a web api. Another way is using jQuery which it looks like you are using. The jQuery ajax equivalent of that curl command is:

$.ajax({
  "url": "https://yourdomain:888/url-to-api",
  "method": "GET",
  "headers": {
    "X-Auth-token": "token"
  }
}).done(function (response) {
  console.log(response);
});
emilpalsson
  • 216
  • 1
  • 4
  • This is what i was looking for i think this will work i've jsut got to over come the 404 error i'm obviously not getting something in their url/api request – adam Wadsworth Jul 02 '18 at 12:27