Getting started overview
Mockaroo provides a service for generating realistic test data through a web interface and a RESTful API. This guide outlines the steps to get started, from account creation to executing your initial data generation request. The process involves defining a data schema that specifies the types and formats of data fields, then leveraging either the web interface for downloads or the API for programmatic retrieval.
To summarize the initial setup:
- Account Creation: Register for a free account on the Mockaroo website.
- API Key Retrieval: Locate your unique API key within your account settings.
- Schema Definition: Use the web interface to define the structure and data types for your test data.
- First Request: Make an API call to Mockaroo's endpoint, referencing your API key and schema, to generate and retrieve test data.
This sequence allows developers to quickly integrate Mockaroo into their development workflows for tasks such as populating databases, mocking API responses, or testing front-end components with varied data sets. Understanding RESTful API principles, which Mockaroo uses, can be beneficial for integration; the IBM documentation on REST APIs provides a foundational understanding of this architectural style.
Here's a quick-reference table for getting started:
| Step | What to Do | Where |
|---|---|---|
| 1. Sign Up | Create a new Mockaroo account. | Mockaroo Homepage (click 'Sign Up') |
| 2. Get API Key | Locate your unique API key in your account settings. | Mockaroo website (after login, typically in 'Account' or 'API' section) |
| 3. Define Schema | Specify data fields, types, and options for your test data. | Mockaroo web interface (New Schema page) |
| 4. Make Request | Construct and execute an API call to generate data. | Your preferred API client (e.g., cURL, Postman, browser) |
Create an account and get keys
To access Mockaroo's features, including its API, you must first create an account. Mockaroo offers a free tier that includes 200 API requests per day and allows for generating up to 1000 records per download, alongside the ability to save up to 10 schemas. This free tier is suitable for initial exploration and development.
- Navigate to the Mockaroo website: Open your web browser and go to Mockaroo's homepage.
- Sign Up: Look for a 'Sign Up' or 'Register' button, typically located in the top right corner of the page. You can often sign up using an email address and password, or through existing social accounts like Google.
- Complete Registration: Follow the on-screen prompts to complete the registration process. This may involve email verification.
- Locate your API Key: Once logged in, your API key is typically displayed prominently in your account dashboard or a dedicated 'API' section. Mockaroo's API keys are essential for authenticating your programmatic requests, ensuring that only authorized applications can access your defined schemas and generate data. An API key acts as a unique identifier and security token, similar to how other services like Stripe API keys function for authentication.
It is crucial to keep your API key secure and not expose it in client-side code or public repositories. Treat it like a password to prevent unauthorized access to your Mockaroo account and usage limits.
Your first request
After creating an account and obtaining your API key, the next step is to define a data schema and then make an API request to generate data. Mockaroo's API is RESTful, meaning you interact with it using standard HTTP methods like GET or POST.
1. Define a Schema
Before making an API request, you need to tell Mockaroo what kind of data you want to generate. This is done by creating a schema in the web interface:
- Log in to Mockaroo: Access your account on the Mockaroo website.
- Create a New Schema: On the main page, you'll see an interface to define fields. Each field requires a 'Field Name' and a 'Type'. Mockaroo offers a wide range of data types, such as 'First Name', 'Email Address', 'Street Address', 'Number', 'Date', and many more specific data types for various testing scenarios.
- Add Fields: For a simple first request, add a few fields. For example:
- Field Name:
id, Type:Row Number - Field Name:
first_name, Type:First Name - Field Name:
email, Type:Email Address - Field Name:
ip_address, Type:IP Address v4
- Field Name:
- Select Format and Rows: At the bottom of the schema definition, choose your desired format (e.g., JSON, CSV) and the number of rows you want to generate. For a first test,
JSONand10rows are good starting points. - Preview Data: Click the 'Preview' button to see sample data generated based on your schema.
- Save Schema (Optional, but recommended): Click 'Save Schema' to store your definition for future use. This will assign a unique ID to your schema, which can be useful for API calls.
2. Make an API Call
Once your schema is defined (either explicitly saved or by setting up fields on the main page), you can make an API request. Mockaroo's API endpoint for generating data is typically structured to include your API key and parameters for the desired data. The most common method is a GET request to the primary data generation endpoint.
The basic structure for an API request to generate data from your current unsaved schema (as configured on the main page) is:
GET https://api.mockaroo.com/api/generate.json?count=10&key=YOUR_API_KEY
Replace YOUR_API_KEY with the actual API key you retrieved from your account. The count parameter specifies the number of rows to generate, and .json indicates the desired output format.
If you have saved a schema, you can reference it by its ID:
GET https://api.mockaroo.com/api/schemas/YOUR_SCHEMA_ID/generate.json?count=10&key=YOUR_API_KEY
Replace YOUR_SCHEMA_ID with the ID of your saved schema (visible in the URL when editing a saved schema or in your schema list).
Example using cURL:
Open your terminal or command prompt and execute a cURL command. This example uses the unsaved schema method:
curl "https://api.mockaroo.com/api/generate.json?count=10&key=YOUR_API_KEY" \
-H "Content-Type: application/json"
You should receive a JSON array containing 10 records generated according to the schema you defined on the Mockaroo website.
Common next steps
After successfully making your first request, you can explore Mockaroo's capabilities further to integrate it more deeply into your development and testing workflows:
- Advanced Schema Definition: Experiment with Mockaroo's extensive list of data types and options. This includes using regular expressions for custom formats, setting null probabilities, defining relationships between fields, and incorporating custom lists of values.
- Saving Multiple Schemas: Create and save multiple schemas tailored for different testing scenarios (e.g., user data, product data, transaction data). This allows you to quickly generate specific datasets without re-defining fields each time.
- Integrating with Testing Frameworks: Incorporate Mockaroo API calls directly into your automated test suites (e.g., using Python's
requestslibrary or Node.js'sfetch). This ensures that your tests always run with fresh, randomized data. - Populating Databases: Generate SQL
INSERTstatements directly from your schema to quickly populate development or staging databases with test data. Mockaroo can output data in various SQL dialects. - Mocking API Endpoints: Use the generated data to create realistic mock responses for your own APIs during front-end development, allowing front-end teams to work independently of back-end readiness.
- Exploring Different Formats: Beyond JSON and CSV, Mockaroo supports XML, SQL, and Excel. Generate data in the format most suitable for your specific application or database.
- Utilizing Webhooks: For more complex integrations, explore Mockaroo's webhook functionality to push generated data to another endpoint automatically. This can be useful for triggering data ingestion pipelines or notifications.
Troubleshooting the first call
If you encounter issues during your first API call, consider the following common troubleshooting steps:
- API Key Verification: Double-check that you have copied your API key correctly. Even a single character mismatch will result in an authentication failure. Your API key is case-sensitive.
- Schema Definition: Ensure that you have a valid schema defined on the Mockaroo website. If you're using the
/api/generate.jsonendpoint without a schema ID, the API relies on the schema currently configured on your main Mockaroo page. If this is empty or malformed, the API may return an error or unexpected data. - Request URL Accuracy: Verify that the entire URL, including the endpoint, parameters (
count,key), and format (.json), is correct. Typos in the hostname or path are common sources of errors. - Internet Connectivity: Confirm that your machine has an active internet connection and can reach
api.mockaroo.com. Network issues can prevent the request from being sent or the response from being received. - Firewall/Proxy Settings: If you are on a corporate network, firewalls or proxy servers might be blocking outbound API requests. Consult your IT department or try making the request from a different network if possible.
- Rate Limits: Remember the free tier's limit of 200 API requests per day. If you've exceeded this, subsequent requests will be rejected. Check your Mockaroo account dashboard for usage statistics.
- Response Status Codes: Pay attention to the HTTP status code returned by the API:
200 OK: Success. Data should be in the response body.401 Unauthorized: Typically indicates an incorrect or missing API key.403 Forbidden: May indicate rate limiting or insufficient permissions for the action.404 Not Found: Incorrect API endpoint or schema ID.5xx Server Error: An issue on Mockaroo's side. If persistent, check their status page or contact support.
- Error Messages: Read any error messages returned in the API response body carefully. They often contain specific information about what went wrong.