• Who: Anyone who is using the FileMaker Data API and needs to query (find) data within a portal.
  • What: How to Query a FileMaker Portal Via the Data API
  • With: FileMaker Server 17+
  • Why: As of 11/2019, the FileMaker 18 Data API documentation does not show a specific example of how to do a find in a portal.

Problem

Doing a Find request via the Data API is fairly simple and the FileMaker documentation has some good examples, but doing a find within a portal isn’t as clear.

Solution

It turns out that doing a find for data within the portal is also very simple and only requires that you specify the table name along with the field. If you’ve been around FileMaker for a while, this related field naming will likely be familiar (RelatedTable::FieldName).

Let’s use an example of a database of US states and their respective cities. If we want to look for a city with the word “Santa” through the portal on the States layout, we just need to include the table name with the field name like this: Cities::CityName (assuming the table name is Cities). Here’s an example of the “body” section for your API call:

{
  "query": [
    {
      "Cities::CityName": "Santa"
    }
  ]
}

Since we are doing this find within a portal on the States layout, the code above would result in a JSON response with a found set of all states that have a city with the word “Santa” in it, and all cities with the word “Santa” as a subset of each state.

That’s it! Simple and clean, like typical FileMaker. 🙂

Note: even though I found out that doing a “find” through a portal wasn’t that hard, in reality I ended up doing a find directly on the Cities table/layout which had a single related field for the parent State on that layout. I found that the resulting JSON was easier to work with since it did not contain a subset of “portalData” under each State record. Neither way is right or wrong, but it’s worth experimenting with both approaches to see which is right in your scenario.

Hope that helps!