import sys
print(sys.version)
3.7.9 (v3.7.9:13c94747c7, Aug 15 2020, 01:31:08) [Clang 6.0 (clang-600.0.57)]
Let's first import fmrest, its FileMakerError and requests.
import fmrest
print(fmrest.__version__)
from fmrest.exceptions import FileMakerError
import requests
requests.packages.urllib3.disable_warnings()
1.4.0
Now access the FMS and log in.
fms = fmrest.Server('https://10.10.10.10', # https://filemaker.example.org
user='fmsrest',
password='fmsrest',
database='testdatabase', # Using a test database
# The test database contains one table and one layout,
# both are named 'datatypes'
layout='datatypes',
# if you are testing without cert/domain
# you may need the parameter verify_ssl=False here.
verify_ssl=False
)
print(fms)
fms.login()
print(fms)
print()
<Server logged_in=False database=testdatabase layout=datatypes> <Server logged_in=True database=testdatabase layout=datatypes>
Before writing anything to the database, we create an empty record.
new_data = {} # empty dict
empty_record = fms.create_record( new_data )
print(empty_record)
43
The table in the test database contains five fields, one for every field type FM provides, i.e. text, number, date, time and timestamp.
UTF-8 text can also include some characters / code points in the private areas, like the apple-sign ( ).
Date does not accept the ISO 8601 format though, instead use 'MM/dd/yyyy'.
The same applies to the date part in timestamps.
In order to check via the API itself, get https://[your_fms_host_here]/fmi/data/vLatest/productInfo. This will return - at the time of this writing - "dateFormat":"MM/dd/yyyy", "timeFormat":"HH:mm:ss", "timeStampFormat":"MM/dd/yyyy HH:mm:ss".
Apparently, FM accepts time and the time part of a timestamp in two formats. Either use a 24h format or an AM/PM alternative (see below).
new_data_2 = {
'mytext': ' Ͼ Ͽ ༺ ༻ ༼ ༽ ༾ ༿ ᐸ ᐳ ⎨ ⎬ ❮ ❯ ⫷ ⫸ ⸨ ⸩ ﹤ ﹥ < > ',
'mynum': 1234567,
'mydate': '02/22/2022', # month/day/year, with leading zero
'mytime': '9:15:55', # 24h format, no 'AM/PM', see above
'mystamp': '02/22/2022 21:15:55', # no 'AM/PM', see above
}
new_record_2 = fms.create_record(new_data_2)
print(new_record_2)
44
Slightly different input here. We pass a number as a string, a date without a leading zero and we use an AM/PM alternative for the date.
new_data_3 = {
'mytext': 'Любви, мира и счастья!',
'mynum': '667',
'mydate': '2/22/2022', # month/day/year, no leading zero
'mytime': '9:15:55 AM', # use 'AM/PM' format
'mystamp': '2/22/2022 9:15:55 PM', # use 'AM/PM'
}
new_record_3 = fms.create_record(new_data_3)
print(new_record_3)
45
Related issue #42 is here: https://github.com/davidhamann/python-fmrest/issues/42#issuecomment-1039211158 .