I tried to operate Filemaker using Python.
server windows server 2012 R2 Filemaker server 17
client windows 10 pro office 2016
Python 3.8.1 Pycharm Community Edition 2020.2
Search and update the appropriate database uploaded to the Filemaker server. The envisioned work is master maintenance. I think that Filemaker is often used like CRM, but I think it would be convenient if the master could be poured from the accounting system. Well, maybe I should do it by hand.
It is assumed that Filemaker Server has a suitable database. It is assumed that there are already users who can access this database with the Web API published. It is assumed that the certificate for SSL communication has not been installed.
Use requests. Please import.
headers = {'Authorization': 'Basic XXXXXXXXXXXXXXXX', 'Content-Type': 'application/json'}
r_post = requests.post(https://[hostname]/fmi/data/v1/databases/[databasename]/sessions', headers=headers, verify=False)
What was written in Excel can be realized in just two lines! Great Python. After Basic, copy the idpw base64 encoded string. There may be a better way around here. Set [hostname] and [databasename] according to your environment.
headers = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'}
query = {'query': [{"Search field name": keyword}]} r_post = requests.post( https://[hostname]/fmi/data/v1/databases/[databasename]/layouts/[layoutname]/_find, json=query, headers=headers, verify=False)
It's very easy. It seems that there are two ways to specify json and data in requests.post, but if Filemaker is the other party, json is easy. For the search keyword, it seems that you can use how to specify in the search mode of Filemaker, such as * or =.
headers = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'}
fieldData = {'fieldData': {'Update target field name': value1,'Update target field name': value2}} r_post = requests.patch(https://[hostname]/fmi/data/v1/databases/[databasename]/layouts/[layoutname]/records/[recordId], json=fieldData, headers=headers, verify=False) It took me two hours to find out that the method was a patch ... Not enough devotion.
Now you can read your CSV file line by line and partially update the master database on FileMaker. If you want to replace all the data at once, you don't have to do this annoying thing.
Recommended Posts