Examples for RAW Endpoints

The Vitruvi Functions from the previous section can be used in a number of ways to reference the RAW and _Query API endpoints. The following M-code examples are provided for reference.

RAW API Endpoints

When querying the raw API endpoints, please use the API documentation for a list of all the app and model name combinations available along with the field list.

Example 1 - Simple RAW query

let 

    // Simplest example - just call the endpoint for a given model and view the results
    // In this example, the filter, field list and display name lists are just set to null.
    // This should only be used when exploring the data. To limit the load on the server, 
    // field selections and/or filtering should be used.
    AccountTable = fVitruviPagedQuery("/api/v1/raw/core/account/", 3000, null, null, null)

in
    AccountTable

Example 2 - Select Fields

let 

    // This example builds on the previous example by selecting a subset of fields to be returned. 
    // This helps keep your data models small and improve query performance.
    
    // Start by creating an M list containing the names of all the fields you want to query
    AccountFields = {"id","email","first_name","last_name","is_active"},
    
    // Now pass the field list into the Vitruvi function
    AccountTable = fVitruviPagedQuery("/api/v1/raw/core/account/", 3000, null, AccountFields, null)

in
    AccountTable

Example 3 - Display Names

let 

    // The fields in Vitruvi are "snake case" - that is all lower case and underscores for spaces. Sometimes it is 
    // cleaner for the query to return cleaner display names. This can be done by also supplying a list of display 
    // names that corresponds to the field names list.

    // Start by creating an M list containing the names of all the fields you want to query
    AccountFields = {"id","email","first_name","last_name","is_active"},

    // Then create an M list containing the display names for the corresponding fields you want to query
    AccountDisplayNames = {"Account Id","Email","First Name","Last Name","Is Active"},

    // Now pass both the field and display name lists into the Vitruvi function
    AccountTable = fVitruviPagedQuery("/api/v1/raw/core/account/", 3000, null, AccountFields, AccountDisplayNames)

in
    AccountTable

Example 4 - Simple Filtering

let 

    // Returning ALL records in a given model is often unnecessary and, again, leads to large data models 
    // and poor performance. In this example, we will apply a simple filter to only get the "active" accounts.

    AccountFields = {"id","email","first_name","last_name","is_active"},
    AccountDisplayNames = {"Account Id","Email","First Name","Last Name","Is Active"},

    // Create a record with a field name equal to your filter criteria and a value to apply to the criteria
    // In this case, we are applying a simple "equals" criteria to the field is_active.
    // For a full list of all the filter criteria, please see the Filtering Raw APIs wiki page.
    AccountFilter = [is_active="True"],

    // Now pass the filter into the Vitruvi function along with both the field and display name lists
    AccountTable = fVitruviPagedQuery("/api/v1/raw/core/account/", 3000, AccountFilter, AccountFields, AccountDisplayNames)

in
    AccountTable

Example 5 - Advanced Filtering

let 

    // This example will demonstrate how to apply compaound criteria to the filter. For more information on how
    // filters work on the RAW endpoints, please see the Filtering Raw APIs wiki page.

    AccountFields = {"id","last_login","email","first_name","last_name","is_active"},
    AccountDisplayNames = {"Account Id","Last Logged In","Email","First Name","Last Name","Is Active"},

    // Compound filters work by simply adding more M fields to your filter record. In this case, lets assume that 
    // we only want records where the account is active, the user's first name starts with B but you DON'T want to 
    // see records that last logged in prior to the start of 2022. The filter would look like this:
    AccountFilter = [is_active="True", first_name__startswith="B", not__last_login__lt="2022-01-01"],

    // Now pass the filter into the Vitruvi function along with both the field and display name lists
    AccountTable = fVitruviPagedQuery("/api/v1/raw/core/account/", 3000, AccountFilter, AccountFields, AccountDisplayNames)

in
    AccountTable