In [1]:
# hide ssl warnings for this example.
import requests
requests.packages.urllib3.disable_warnings()
This is a short example on finding records with python-fmrest.
In [2]:
import fmrest
In [3]:
fms = fmrest.Server('https://10.211.55.15',
user='admin',
password='admin',
database='Contacts',
layout='Demo',
verify_ssl=False
)
fms.login()
Out[3]:
We want to find records in Contacts where the name field matches 'John Doe'.
In [4]:
find_query = [{'name': 'John Doe'}]
foundset = fms.find(find_query)
foundset
Out[4]:
We have our foundset and can iterate through it. fetched_records=0 means that we haven't consumed the Foundset yet.
In [5]:
for record in foundset:
print(record)
In [6]:
foundset
Out[6]:
Looks like Record 44 is our only record in the foundset. Let's look at it:
In [7]:
record = foundset[0]
print(record.keys()) # all the field names on the layout, including portals
print(record.values()) # all the value corresponding to the field names
Above we can see all available keys and values. If we want to acces a value, we can use the Record's attributes:
In [8]:
record.name
Out[8]:
In [9]:
record.drink
Out[9]:
The FileMaker Data API supports the same operators FileMaker Pro does. So let's go ahead and broaden our search.
In [10]:
find_query = [{'name': 'John*'}]
foundset = fms.find(find_query)
for record in foundset:
print(record.id, record.name)
Using the wildcard we match all the Johns.
Multiple find requests are also supported. Again, just like in FileMaker Pro.
Let's find all Johns and Joes, but not John Does.
In [11]:
find_query = [
{'name': 'John'},
{'name': 'Joe'},
{'name': 'John Doe', 'omit': 'true'}
]
foundset = fms.find(find_query)
for record in foundset:
print(record.name)
You can control the order of the results by specifying the sort parameter.
In [12]:
order_by = [{'fieldName': 'name', 'sortOrder': 'descend'}] #descending
foundset = fms.find(find_query, sort=order_by)
for record in foundset:
print(record.name)
print('---')
order_by = [{'fieldName': 'name', 'sortOrder': 'ascend'}] #ascending
foundset = fms.find(find_query, sort=order_by)
for record in foundset:
print(record.name)
To create more efficient requests, you can limit the data being returned.
Only return from the second record.
In [13]:
foundset = fms.find(find_query, sort=order_by, offset=2)
for record in foundset:
print(record.name)
Only return one record.
In [14]:
foundset = fms.find(find_query, sort=order_by, limit=1)
foundset[0].name
Out[14]:
Of course, you can combine these parameters as you like. Defaults are offset 1 (which is the first record), limit 100.
By specifying portals, you can prevent certain portal data to be returned, even if portals are present on your layout.
In [15]:
portals = [{'name':'notes', 'offset':1, 'limit': 1}]
foundset = fms.find(find_query, portals=portals)
for row in foundset[0].portal_notes:
print(row['Notes::note'])
The name is the object name as specified in the Inspector in FileMaker Pro. Offset and limit are optional with default values 1 and 50.
Not specifying the portals parameter will return all portals on the layout with the default offset and limit.