Add JSON data source
Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher
This article will cover how to create a new JSON-based data source in Service solutions.
Getting started
You will need the following tools and facilities:
Know how to use API key in Service solutions.
This article will skip over additional information on authentication and authorization.
Curl tool.
Any other REST client will work, but the examples will be built for curl.
JSON file.
JSON scheme.
Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.
Internet access.
Create a data source
To create a data source, send CREATE request to {host_name}/api/data/v1/DataSources .
Example request body:
{
"name": "fakeAPI",
"connectionString": "Json=aHR0cHM6Ly9qc29ucGxhY2Vob2xkZXIudHlwaWNvZGUuY29tL3Bvc3Rz;JsonSchema=eyJ0eXBlIjoiYXJyYXkiLCJpdGVtcyI6eyJ0eXBlIjoib2JqZWN0IiwicHJvcGVydGllcyI6eyJ1c2VySWQiOnsidHlwZSI6Im51bWJlciJ9LCJpZCI6eyJ0eXBlIjoibnVtYmVyIn0sInRpdGxlIjp7InR5cGUiOiJzdHJpbmcifSwiYm9keSI6eyJ0eXBlIjoic3RyaW5nIn19fX0=;Encoding=utf-8",
"subscriptionId": "604f52e1261a3c19104c0e25",
"connectionType": "JSON"
}
Where
name— data source name (it will be displayed in the designer when selected).connectionString— connection string, in case of JSON, it consists of 3 elements:Json— JSON file or http/https link encoded in base64;JsonSchema— schema describing JSON file structure encoded in base64;Encoding— encoding, it should always be passed to dfgutf-8.
subscriptionId— ID of the workspace (subscription) to which the data source will be attached.connectionType— connection type, this guide usesJSON.
Example request:
curl -X POST "{host_name}/api/data/v1/DataSources" -H "accept: text/plain" -H "Content-Type: application/json-patch+json" -d "{ \"name\": \"fakeAPI\", \"connectionString\": \"Json=aHR0cHM6Ly9qc29ucGxhY2Vob2xkZXIudHlwaWNvZGUuY29tL3Bvc3Rz;JsonSchema=eyJ0eXBlIjoiYXJyYXkiLCJpdGVtcyI6eyJ0eXBlIjoib2JqZWN0IiwicHJvcGVydGllcyI6eyJ1c2VySWQiOnsidHlwZSI6Im51bWJlciJ9LCJpZCI6eyJ0eXBlIjoibnVtYmVyIn0sInRpdGxlIjp7InR5cGUiOiJzdHJpbmcifSwiYm9keSI6eyJ0eXBlIjoic3RyaW5nIn19fX0=;Encoding=utf-8\", \"subscriptionId\": \"604f52e1261a3c19104c0e25\", \"connectionType\": \"JSON\"}"
Example answer:
{
"id": "60648953db44d83f9c6da98f",
"name": "fakeAPI",
"connectionType": "JSON",
"connectionString": "Json=aHR0cHM6Ly9qc29ucGxhY2Vob2xkZXIudHlwaWNvZGUuY29tL3Bvc3Rz;JsonSchema=eyJ0eXBlIjoiYXJyYXkiLCJpdGVtcyI6eyJ0eXBlIjoib2JqZWN0IiwicHJvcGVydGllcyI6eyJ1c2VySWQiOnsidHlwZSI6Im51bWJlciJ9LCJpZCI6eyJ0eXBlIjoibnVtYmVyIn0sInRpdGxlIjp7InR5cGUiOiJzdHJpbmcifSwiYm9keSI6eyJ0eXBlIjoic3RyaW5nIn19fX0=;Encoding=utf-8",
"dataStructure": "<JsonDataSourceConnection ConnectionString=\"rijcmlqrcq6OJBTPt0pNFvRuRtDUSHSHLQy/QlNolifTTaTjsrExzdbf1ifpPblp655sducwkD1lEVzxVZF8qRuE0NT6UkyTr7kwjGItFOwh7DBsOyL6QkQY4FOZ2ki8Al2R30gpXs6nMUGg1BRwCF0rj3+QvmXbj+2t8x5RerR5y7inP1R+oCuo0wvfcTeOMfYfZrjdE3whziFh5Qn3mR7vaevmV9peDWQ3LYyK2ec3KpGVeEXSqM+10WyL4ahY7EHuQIzIZROGFGKfW50cUYwdillhKy24gNdsUzi5klG66DDQtCKEOLbNutDvA0xqCTW3MvRNORSbvckL6g3gM+cStJ5PQ2XUjF9yz9zdwmramnXI6k+MK8V9lrMkc0XFkDMHOxDlfG2jHhkFuUTgmiKp7hQMg==\">\r\n <JsonTableDataSource Name=\"JSON\" DataType=\"FastReport.Data.JsonConnection.JsonParser.JsonArray\" Enabled=\"true\" TableName=\"JSON\">\r\n <Column Name=\"index\" DataType=\"System.Int32\"/>\r\n <Column Name=\"item\" DataType=\"FastReport.JsonBase\">\r\n <Column Name=\"userId\" DataType=\"System.Double\"/>\r\n <Column Name=\"id\" DataType=\"System.Double\"/>\r\n <Column Name=\"title\" DataType=\"System.String\"/>\r\n <Column Name=\"body\" DataType=\"System.String\"/>\r\n </Column>\r\n <Column Name=\"array\" DataType=\"FastReport.JsonBase\"/>\r\n </JsonTableDataSource>\r\n</JsonDataSourceConnection>\r\n",
"subscriptionId": "604f52e1261a3c19104c0e25",
"editedTime": "2021-03-31T14:38:10.5792982Z",
"editorUserId": "2df79f83-07f1-41ba-96b5-7757bbf377df",
"createdTime": "0001-01-01T00:00:00",
"creatorUserId": "2df79f83-07f1-41ba-96b5-7757bbf377df",
"isConnected": true
}