Using calculated fields
Calculated fields provide a simple way to perform standard SQL calculations (count, sum, min, max, etc.) in an API call.
Try these examples in the 'API Docs' tab of the DreamFactory Admin Console or from the command line with cURL.
API Docs Screenshot
Example - Use a calculated field to calculate the sum of the 'amount' field in a transactions table.
Say we have a 'transaction' table with an 'amount' field. We need to perform an API call on a set of records in the transaction table that returns the total amount.
All we need to do is set up a "virtual" calculated field that defines the calculation. To set up a calculated field, navigate to the Schema tab and click to add a new field. In this example, we will add a field called 'amount_total' and fill in the field definition as shown in the screenshot below.
Now we can make API calls to the 'transaction' table and GET the total amount for the returned set of records.
- Table name: transaction
- Fields parameter in API call:
- Request URL: