Generate Test Data
To generate test data, you need to know your workspace identifier and Data Model identifier. The sample code uses a workspaceId
of 123456
. Use the actual ID values of your workspace and Data Model.
You can generate data for a data model that is stored in the Asset Repository, or you can pass the Data Model in a request to the generate
endpoint.
Generate Data for a Data Entity (Asset Repository)
Assuming you have stored the Data Model in the Asset Repository and have the id of the asset (dataModelId), you can generate data using the following call.
API Explorer: /testdata
Optionally, the body can contain a so-called Model Override; for more information, see Data Structures.
The response contains a JSON array with generated data and billingLimits
information.
The billingLimits conveys information whether the billing limits have been applied or not.
In case of a Data Model validation error, a 400 response code and a detailed validation report are retuned.
Generate Test Data
curl 'https://tdm.blazemeter.com/api/v1/workspaces/123456/datamodels/55/generate'
-X POST \
-H 'accept: application/json'
-H 'Content-Type: application/json'
Sample 200 response
{
"api_version": 1,
"total": 5,
"billingLimits": {
"total": 10000,
"entity": {
"user": {
"apply": true,
"applied": false,
"requested": 5,
"generated": 5
}
}
},
"user": [
{ "randomName": "RE5ONP3" },
{ "randomName": "YDBgwvWn3" },
{ "randomName": "c0BcQJg" },
{ "randomName": "HPgVyan" },
{ "randomName": "yanUhmHqs" }
],
"request_id": "a2c28c09"
}
Generate Data for a Data Entity (Single Entity)
In some situations you don’t have a Data Model stored in the Asset Repository,
but you store it somewhere else, or you keep it in memory.
To generate data for such a model, use the /generate
endpoint.
Note that this endpoint generates data for one entity only
(use /generatefile
below if you need to generate all entities).
API Explorer: /testdata
The following JSON sample provides a more readable version of the content contained in the above curl
example. This example represents the attributes and values contained in the -d
flag of the curl
example.
Generate Test Data
curl 'https://tdm.blazemeter.com/api/v1/workspaces/123456/testdata/generate?entityName=user' \
-X POST \
-H 'accept: application/json'
-H 'Content-Type: application/json' \
-d '{ "data": {
"type": "datamodel",
"attributes": {
"model": {
"schema": "http://perforce.com/blazedata/schema",
"id": "datamodels/testParameters", "title": "Test Parameters",
"description": "", "kind": "tdm", "type": "object",
"entities": {
"user": {
"title": "user", "type": "object",
"properties": { "name": { "type": "string" } },
"requirements": { "name": "randText(3, 10)" },
"targets": { "defaultCsv": { "type": "csv", "file": "user.csv", "isHeadless": false } },
"datasources": [], "repeat": 1
}
}
},
"context": { "csvs": [] }
}
}}'
The following parameters are the base parameters required to generate test data.
Generate Test DataGenerate Test Data POST Body (JSON)
{
"data": {
"type": "datamodel",
"attributes": {
"model": {
"schema": "http://perforce.com/blazedata/schema",
"id": "datamodels/testParameters",
"title": "Test Parameters",
"description": "",
"kind": "tdm",
"type": "object",
"entities": {
"user": {
"title": "user",
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"requirements": {
"name": "randText(3, 10)"
},
"targets": {
"defaultCsv": {
"type": "csv",
"file": "user.csv",
"isHeadless": false
}
},
"datasources": [],
"repeat": 1
}
}
},
"context": {
"csvs": []
}
}
}
}
}
Generate Test Data Response Attributes
Attributes
-
description
stringThe description of the new Data Model
-
properties
stringrequired
Defines the data types of the values to generate. For example, "email": { "type": "string"} or "age": {"type": "integer"}. List the same attributes as for the requirements.
-
requirements
stringrequired
Defines the rules what data to generate for each property. For example, {"name":"randText(5, 10)"}. List the same attributes as for the properties.
A requirement can reference the value of another property by using the dollar sign notation. You can concatenate values using the plus operator. For example, in "name": "randlov(0, seedlist('firstnames'))", "email": "$name + '@acme.com'" the value of the property name is referenced as part of the property email.
For more information on data generation functions, see Get List of Seed Lists, Get List of Data Generator Functions, and Get List of Card Issuers.
-
required
stringrequired
The list of properties that are required.
Response200 OK
{
"api_version": 1,
"total": 1,
"billingLimits": {
"total": 10000,
"entity": {
"user": {
"apply": true,
"applied": false,
"requested": 1,
"generated": 1
}
}
},
"result": [
{
"name": "2Gu3Nrxq"
}
],
"request_id": "d712a082"
}
Generate Data for all Data Entities
Use /generatefile if you need data generated for all Data Entities in the Data Model.
/api/v1/workspaces/123456/datamodels/55/generatefile
API Explorer: /datamodels
/api/v1/workspaces/123456/testdata/generatefile
API Explorer: /testdata
These endpoints work the same as their “generate” counterparts, but always generate the whole model. You can use the accept
HTTP header to control whether you want a file to be retuned, or just generate a JSON document. If you specify text/csv
, a CSV file is generated. In all other cases, a JSON document is returned with application/json
content-type.