Filtering by a Connected Record

The examples below use two objects: Employees and Companies, where many Employees connect with one Company. The connection field is on the employee, and it is called Employed By. Query for Employees connected to a specific Company using:

Object-Based GET Request

  1. Identify the parent record to filter child records on. Make a request for this record by querying the parent object with a filter for the record’s Display (or any other unique) field.

    • Example: Identify the Company record by which you want to filter a request for Employees. Make a request for this record by querying the Company object with a filter for the record’s Company Name, for instance.
  2. Locate the Connection field, which is usually on the child object. Select it in your Builder and note the field key at the end of your URL.

    • Example: Employed By field on the Employee Object. Let’s say the its field key is field_12.
  3. Add your filter using the Connection field, the is operator, and the parent record’s ID for a value.

    • Example: {“field”:“field_12”, “operator”:“is”, “value”:“574ec622dadf69d041755605”}

A complete Object-based request route, where Company is object_1, would look like this:
https://api.knack.com/v1/objects/object_1/records?filters=[{"field":"field_12", "operator":"is", "value":"574ec622dadf69d041755605"}]

Example

👍

Take a look at our JavaScript example which makes a pair of Object-based GET requests to retrieve all child records with a specific parent!

View-Based GET Request

In this example, the page we will be working with has a detail view of a Company, but also contains a table view showing connected Employees. The table data source is configured as "Displaying Employee records connected to this page's Company record."

  1. Identify the scene URL and parent Company record id for which children records you want to retrieve. Viewing the page in the Live App will give you this data in the URL.
    • Example: https://my-account.knack.com/my-app#companies/company-details/5d65bad5614e4d001047b585/

Parameter

Value

Scene URL

company-details

Parent Record Id

5d65bad5614e4d001047b585

  1. Following the View-Based GET examples we can construct a URL to retrieve the Employee records in the table view. To do this we will need to pass the scene URL and parent Company record id as a URL parameter in the request.
    • Example: ?company-details_id=5d65bad5614e4d001047b585
    • Note: The parameter is the scene URL suffixed with "_id"

A complete View-based request route, where the Employees table view is view_2, would look like this: https://api.knack.com/v1/scenes/scene_1/views/view_2/records?company-details_id=5d65bad5614e4d001047b585


Did this page help you?