How do I use an API to query data from a dataset?

I would like to upload a small dataset, and then use a Mockaroo API to return this dataset based on where clauses through the URL.

Consider this example, here is the URL:


Where :username is a username found in a static dataset inserted into Mockaroo. The API is based off a schema, that is strictly routed, 1:1 to this dataset.

So you come to this URL, pass the username, which goes to the API, which goes to the schema, which goes to the dataset, and returns a row, or rows where the column = the parameter :username.

How would I do this in the script API?

I think what you want to do is add a Formula column to your schema and use the from_dataset() function to pull out values based on a parameter.

So something like:

from_dataset("My Data", "some column", username: request_params['username'])

This would pull the value of some_column from the dataset called “My Data” where the username column in the dataset matches the value of the username parameter in the query string of the API request.

From the docs:

from_dataset("dataset", "column", join_criteria) => Fetches a value from a dataset.
For example, from_dataset(“People”, “name”, id: person_id) returns the value of the “name” column from the “People” dataset where the id column matches the person_id column in the current schema.


So, I actually tried that. Here is my code in my API handler script:’

schema "mh_providers_static" from_dataset("mh_providers_static", "resourceId", resourceId: request_params['id'])

But I always get this error when I try this:
{"error":"method method_missing’ for class Api::VirtualServiceSandbox' is private"}

Which makes me think that the from dataset function is a private function/method and is not callable by the API library.

You need to use from_dataset() in a Formula column in your schema, not in the API handler.

from_dataset() is private, not available for all user except the user creating it. Is that right?

I have a similar scenario. I have done what you suggested, use from_dataset() in a Formula column. Is there any way to limit the result to just the number of rows it matches?
Currently it goes by the # of Rows mentioned in the schema and repeats the data when there is less.
In other words, if my dataset has only 2 rows matching the request parameter, but the schema is configured to return 10 rows, it gives me 10 rows with duplicates.