0

Python support.

Hi Ninox.

I'd like to run a Python program to pull some information from a serial interface and put it in a variable that will be put into a record entry. Are you guys interfacing with Python yet? Or any other external calls?

Thank you.

John

8 replies

null
    • Mconneen
    • 5 yrs ago
    • Reported - view

    @John, an interesting use case.  Using the Ninox Cloud version, your Python application can post into your Ninox Cloud database.   For LOCAL database, they currently do not support an API. 

    See https://ninoxdb.de/en/manual/api/rest and browse for "Update Record".. 

    • francescostefanello
    • 1 yr ago
    • Reported - view

    Hi, thank you for support, the link is not working... can you please suggest any other place where to get a similar documentation?

    • Fred
    • 1 yr ago
    • Reported - view

    Here is the link to the latest documents on API from Ninox.

    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    here you can found an great API manager in JavaScript written by Axel Rothe : https://github.com/AxelRothe/ninox

    To turn how to call Ninox API with Python language, there is many way :

    - use REST software (like Advanced REST Client from MuleSoft) to test your connexion and retrieve corresponding code :

    - use one curl to Python converter to convert the code from Ninox documentation : https://sqqihao.github.io/trillworks.html

    • francescostefanello
    • 1 yr ago
    • Reported - view

    First of all thanks a lot to Jacques who really helped a lot with patience!

    I wrote a small Python script who scrape some data from Internet:


     

    #data scraped from internet, for example

    # a = 10, b = Paperino, c = Pluto, d = Nonna Papera

    #now i transform the dict in JSON format ready for Ninox

    #it works!

    my_dict = [{

        "fields": {

            "Field1": [a],

            "Field2": [b],

            "Field3": [c],

            "Field4": [d]

        }

    }]

    my_json = json.dumps(my_dict, ensure_ascii=False)

    url = 'https://api.ninox.com/v1/teams/TEAM-ID/databases/DATABASE-ID/tables/TABLE-ID/records'

    headers = {'Authorization': 'Bearer API-KEY','Content-Type': 'application/json'}

    req = requests.post(url, headers=headers, data=my_json)

    print(req.text)


     

    At this point is all OK

     

    But when I try to update a record of the same Table with the PUT command instead of a POST, for example:


    url = 'https://api.ninox.com/v1/teams/TEAM-ID/databases/DATABASE-ID/tables/TABLE-ID/records/1'

    headers = {'Authorization': 'Bearer API-KEY','Content-Type': 'application/json'}

    req = requests.put(url, headers=headers, data=my_json)

    print(req.text)


    I receive this error: 

    {"message":"Internal Server Error"}


    Thx for your attention

    dnnywld

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

      francesco.stefanello Two ways :

      1 : 1: use the post function and simply add in the JSON the id of the record you want to update : https://docs.ninox.com/en/api/public-cloud-apis#create-update-multiple-records-with-post.

      2: with the put function, check the result of the JSON text. I'm surprised that you need to use [] ("Field1":[a],) to insert your variable inside. I feel like it will create an array, not a variable.
      Python exemple :

      import json
      name = "marcel";
      x = {
        "name1": [name],
        "name2" : name,
      }

      result : 

      {"name1": ["marcel"], "name2": "marcel"} (empty)

      See the JSON on Python syntax in W3School : https://www.w3schools.com/python/python_json.asp

    • francescostefanello
    • 1 yr ago
    • Reported - view

    Thank you a lot Jacques, all works perfectly!

    I know that Ninox is written in JavaScript, and I saw your excellent solutions about NativeJS from Ninext.

    Unfortunately I am not familiar with JS and I would really be able to run a Python script from Ninox.  You said that could be really complex, but do you or anyone here know where to find a guide about that?

    Seems that no one ever tried to do that...

    As always thanks for all to you and all Ninox users always ready to help.

Content aside

  • 1 yr agoLast active
  • 8Replies
  • 2076Views
  • 2 Following