In [23]:
# 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.
In [24]:
import fmrest
In [25]:
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.
In [26]:
fms.login()
Out[26]:
In [27]:
foundset = fms.get_records(limit=2)
foundset
Out[27]:
Now we have a foundset instance we can iterate over:
In [28]:
for record in foundset:
print(record)
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:
In [29]:
record = foundset[0]
In [30]:
record.keys()
Out[30]:
Now, if we want to get the name, we just access it via the attribute:
In [31]:
record.name
Out[31]:
...or via the key:
In [32]:
record['drink']
Out[32]:
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.
In [33]:
portal = foundset[0].portal_notes
portal
Out[33]:
We could go through the rows like this
for row in portal:
print(row)
Or access a particular row directly:
In [34]:
row = portal[0]
row
Out[34]:
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):
In [35]:
row['Notes::note']
Out[35]:
Let's logout and destroy our opened session.
In [36]:
fms.logout()
Out[36]: