Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

  • Hi, it appears that I can no longer view the REST API documentation at http://localhost:8080/swagger/index.html when using the latest v3.0.1. I have placed the env.properties in overrides/classes and set swagger=true. However, opening that documentation link returns the following. Could anyone help please. Cheers.

    Can't read swagger JSON from http://localhost:8080/rest/api-docs
    

  • Hi mliu18,

    Were you already logged into Mango before navigating to swagger? That was a change in 3, where now that page will only load after you've logged in.


  • This post is deleted!

  • @phildunlap yes I'm already logged in, and I have tried it on a few different browsers and different computers, still the same
    btw, i'm using the free version, not sure if this matters or not

    edit1: if I try without logging in, this is the message I get, which is different from when I'm logged in

    401 : undefined http://localhost:8080/rest/api-docs
    

  • @phildunlap also, a bit off topic, but could you please help me out with some python code to access the REST API, I can successfully login, but any attempt to retrieve data keeps timing out, here is the code I used in python

    import requests
    import json
    
    s = requests.Session()
    s.headers.update({'Accept': 'application/json', 'Content-Length': '39', 'Content-Type': 'application/json;charset=UTF-8','Cookie':'XSRF-TOKEN=74cf354a-e871-48b6-a1c2-bebb93d00120','X-XSRF-TOKEN':'74cf354a-e871-48b6-a1c2-bebb93d00120'});
    
    #Show session headers
    #print(s.headers)
    
    js = {'username': "admin", 'password': "admin"}
    
    r = s.post('http://localhost:8080/rest/v2/login', data=json.dumps(js))
    
    #Show headers sent
    print( r.request.headers)
    # show returned headers
    print( r.headers)
    
    
    ##you may need to set your X-Xsrf-Token header from the cookie, if so uncomment next line.
    s.headers.update({'X-XSRF-TOKEN' : s.cookies['XSRF-TOKEN']})
    
    #Show Login response JSON
    #print( r.text)
    
    ##Show all data points
    r = s.get('http://localhost:8080/rest/v1/data-points/', timeout=5);
    #print( r.text)
    

    the initial login returns the following header

    {'Date': 'Tue, 16 May 2017 15:03:52 GMT', 'Set-Cookie': 'MANGO8080=1k38gugobccn4d2nrpfc18f6r;Path=/;HttpOnly, XSRF-TOKEN=e4a452ea-6e47-4a12-8547-202eb0b158d4;Path=/', 'Expires': 'Thu, 01 Jan 1970 00:00:00 GMT', 'X-Mango-Default-URI': '/ui/data-point-details/', 'Content-Type': 'application/json;charset=UTF-8', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'SAMEORIGIN', 'Transfer-Encoding': 'chunked'}
    

    however, the second "s.get" receives the following error message

    Traceback (most recent call last):
    
      File "<ipython-input-33-fae73997cd8c>", line 1, in <module>
        r = s.get('http://localhost:8080/rest/v1/data-points/', timeout=5);
    
      File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 501, in get
        return self.request('GET', url, **kwargs)
    
      File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 488, in request
        resp = self.send(prep, **send_kwargs)
    
      File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 609, in send
        r = adapter.send(request, **kwargs)
    
      File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 499, in send
        raise ReadTimeout(e, request=request)
    
    ReadTimeout: HTTPConnectionPool(host='localhost', port=8080): Read timed out. (read timeout=5)
    

    On the other hand, if I do it in the browser (after logging in to the web UI), the full list of points is returned.


  • That shouldn't matter. The next thing I'd wonder is, is the Mango API module installed?

    After that, are you sure swagger.enabled=true in your Mango/overrides/properties/env.properties file. You can also tell if swagger should be working as it takes a very long time during startup around 88%.


  • @phildunlap thanks!! made a very silly mistake, i put the env.properties in the overrides/classes folder by mistake...

    however, I'm still unable to get the REST API stuff to work in python. would really appreciate it if you could have a look, cheers.


  • Looks like there's a couple issues there to be dealt with. I got it working here:

    import requests
    import json
    
    s = requests.Session()
    s.headers.update({'Accept': 'application/json', 'Content-Length': '39', 'Content-Type': 'application/json;charset=UTF-8','Cookie':'XSRF-TOKEN=74cf354a-e871-48b6-a1c2-bebb93d00120','X-Xsrf-Token':'74cf354a-e871-48b6-a1c2-bebb93d00120'});
    
    #Show session headers
    #print(s.headers)
    
    js = {'username': "admin", 'password': "admin"}
    
    r = s.post('http://localhost/rest/v2/login', data=json.dumps(js))
    
    #Show headers sent
    #print( r.request.headers)
    # show returned headers
    #print( r.headers)
    
    s.headers.update({'Cookie' : r.headers['Set-Cookie']})
    
    #print( s.cookies )
    del s.headers["Content-Length"]
    del s.headers["Content-Type"]
    del s.headers["X-Xsrf-Token"]
    
    ##Show all data points
    r = s.get('http://localhost/rest/v1/data-points', timeout=5);
    print( r.text)
    #print( r.status)
    

    Main points, 1. Had to delete those headers for the POST body, 2. Because the cookie is explicitly set as a header, it must explicitly be updated (I think).


  • @phildunlap just an update on this, I managed to get it working this time, the culprit is in fact those extra headers, however in my case, I had to delete the following. It stops working if I delete the header "X-Xsrf-Token".

    del s.headers["Content-Length"]
    del s.headers["Content-Type"]
    del s.headers["Cookie"]
    

    Anyway, thank you for your prompt responses. Cheers.


  • Certainly! Thanks for sharing what got it working for you.