This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

mfws and python

Former Member
Former Member
I'm currently starting a project to interact with mfiles using python.  I've managed to get authentication tokens with this code:

#testbed for requests (http api) and mfiles REST interface
import requests
import json
#try to retrieve authentication tokens
authentication = 'localhost/.../authenticationtokens.aspx'
data = json.dumps({"Username":"yourname", "Password":"yourpassword"})
h= requests.post(authentication, data = data)
print(h.reason,'reason')
print('#')
print(h._content)

Anyone interested in working on this jointly?

New discovery.  The data line must be changed to :

data = json.dumps({"Username":"yourname", "Password":"yourpassword",
                  "VaultGuid":"{1E5F2435-AFB8-4A7D-92D3-45B04D1268D9}"})

or the token won't work for individual vault access.

Parents
  • Former Member
    Former Member
    The project is coming along nicely. The following makes a quick graphical window to test the quick search function:

    #testbed for requests (http api) and mfiles REST interface
    import requests #third party. all others std library
    import json
    from tkinter import *
    from tkinter.ttk import *

    baseurl = 'http://localhost/m-files/REST'

    def authenticate():
    authentication = ''.join((baseurl, '/server/authenticationtokens.aspx'))
    data = json.dumps({
    "Username": "yourname", "Password": "yourpassword",
    "VaultGuid": "{1E5F2435-AFB8-4A7D-92D3-45B04D1268D9}"
    })
    return json.loads(requests.post(authentication, data = data).text)['Value']

    def search():
    #reads search term from entry widget, joins it to the url
    #queries mfiles using authentication tokens and url
    #returns the query results
    searchterm = Ent.get()
    url = ''.join((baseurl, "/Objects.aspx?q=", searchterm))
    headers = {"content-type":"aplication/json", 'X-Authentication':authtoken}
    condition_results(json.loads(requests.get(url, headers=headers).text))

    def condition_results(results):
    #displays one line for each item, the content of the line being the
    #value of key 'EscapedTitleWithID'. Could be any of: ['AccessedByMeUtc',
    #'CheckedOutAt', 'Files', 'EscapedTitleWithID', 'ObjVer', 'AccessedByMe',
    #'CheckedOutAtDisplayValue', 'VisibleAfterOperation', 'LastModified',
    #'ObjectCheckedOutToThisUser', 'SingleFile', 'LastModifiedDisplayValue',
    #'ObjectVersionFlags', 'ObjectCheckedOut', 'Title', 'LastAccessedByMe',
    #'CheckedOutAtUtc', 'PathInIDView', 'DisplayID', 'LastModifiedUtc',
    #'Class', 'ObjectGUID', 'CheckedOutTo', 'CreatedUtc', 'Score',
    #'CreatedDisplayValue', 'ThisVersionLatestToThisUser',Created']
    print('****************************')
    for item in results['Items']:
    print(item['EscapedTitleWithID'])
    print('****************************')

    if __name__ == '__main__':
    authtoken = authenticate()
    trial = Tk()
    Label(trial, text='test for vault lookup').grid()
    Button(trial, text='Go', command=search).grid()
    Ent = Entry(trial)
    Ent.grid(column=1, row=1)
    trial.mainloop()
Reply
  • Former Member
    Former Member
    The project is coming along nicely. The following makes a quick graphical window to test the quick search function:

    #testbed for requests (http api) and mfiles REST interface
    import requests #third party. all others std library
    import json
    from tkinter import *
    from tkinter.ttk import *

    baseurl = 'http://localhost/m-files/REST'

    def authenticate():
    authentication = ''.join((baseurl, '/server/authenticationtokens.aspx'))
    data = json.dumps({
    "Username": "yourname", "Password": "yourpassword",
    "VaultGuid": "{1E5F2435-AFB8-4A7D-92D3-45B04D1268D9}"
    })
    return json.loads(requests.post(authentication, data = data).text)['Value']

    def search():
    #reads search term from entry widget, joins it to the url
    #queries mfiles using authentication tokens and url
    #returns the query results
    searchterm = Ent.get()
    url = ''.join((baseurl, "/Objects.aspx?q=", searchterm))
    headers = {"content-type":"aplication/json", 'X-Authentication':authtoken}
    condition_results(json.loads(requests.get(url, headers=headers).text))

    def condition_results(results):
    #displays one line for each item, the content of the line being the
    #value of key 'EscapedTitleWithID'. Could be any of: ['AccessedByMeUtc',
    #'CheckedOutAt', 'Files', 'EscapedTitleWithID', 'ObjVer', 'AccessedByMe',
    #'CheckedOutAtDisplayValue', 'VisibleAfterOperation', 'LastModified',
    #'ObjectCheckedOutToThisUser', 'SingleFile', 'LastModifiedDisplayValue',
    #'ObjectVersionFlags', 'ObjectCheckedOut', 'Title', 'LastAccessedByMe',
    #'CheckedOutAtUtc', 'PathInIDView', 'DisplayID', 'LastModifiedUtc',
    #'Class', 'ObjectGUID', 'CheckedOutTo', 'CreatedUtc', 'Score',
    #'CreatedDisplayValue', 'ThisVersionLatestToThisUser',Created']
    print('****************************')
    for item in results['Items']:
    print(item['EscapedTitleWithID'])
    print('****************************')

    if __name__ == '__main__':
    authtoken = authenticate()
    trial = Tk()
    Label(trial, text='test for vault lookup').grid()
    Button(trial, text='Go', command=search).grid()
    Ent = Entry(trial)
    Ent.grid(column=1, row=1)
    trial.mainloop()
Children
No Data