# hide ssl warnings for this test.
import requests
requests.packages.urllib3.disable_warnings()
This is a short example on how to login, get a foundset from a database layout, read field values, and eventually logout.
import fmrest
fms = fmrest.Server('https://10.211.55.15',
user='admin',
password='admin',
database='Contacts',
layout='Demo',
verify_ssl=False
)
The login method obtains the access token.
fms.login()
'd4a1304c20b20390f1dca3dac190a8bb0fe5b5aca5d7c40562d4'
foundset = fms.get_records(limit=2)
foundset
<Foundset consumed_records=0 is_complete=False>
Now we have a foundset instance we can iterate over:
for record in foundset:
print(record)
<Record id=2 modification_id=7 is_dirty=False> <Record id=3 modification_id=8 is_dirty=False>
We have two records in our foundset. Let's see what is in them:
Let's look at the available keys (fields) of the first record in the foundset:
record = foundset[0]
record.keys()
['id', 'name', 'drink', 'portrait', 'creation', 'modification', 'recordId', 'modId', 'portal_notes']
Now, if we want to get the name, we just access it via the attribute:
record.name
'David'
...or via the key:
record['drink']
'Coffee'
By looking at the keys, we can see that we also have portals on our layout (keys starting with "portal_"). Let's look at portal_notes
.
It is, again, a foundset instance.
portal = foundset[0].portal_notes
portal
<Foundset consumed_records=0 is_complete=False>
We could go through the rows like this
for row in portal:
print(row)
Or access a particular row directly:
row = portal[0]
row
<Record id=2 modification_id=None is_dirty=False>
We get back a record instance just like the ones before. Note, though, that we access fields in portal rows with the table occurrence prefix (just like in FileMaker Pro):
row['Notes::note']
'A note for David.'
Let's logout and destroy our opened session.
fms.logout()
True