Adding a JSON data source
This article walks you through the process of creating a new JSON data source in FastReport Сloud.
Getting Started
You will need the following tools and features:
Knowledge of using API key in FastReport Сloud.
This article will skip additional information on authentication and authorization.
Curl tool.
Any other REST client will do, but the examples will be built for curl.
JSON file.
JSON schema.
Active FastReport Сloud subscription.
Access to the Internet.
Creating a data source
To create a data source, send a CREATE request to https://fastreport.cloud/api/data/v1/DataSources
.
Request body example:
{
"name": "fakeAPI",
"connectionString": "Json=aHR0cHM6Ly9qc29ucGxhY2Vob2xkZXIudHlwaWNvZGUuY29tL3Bvc3Rz;JsonSchema=eyJ0eXBlIjoiYXJyYXkiLCJpdGVtcyI6eyJ0eXBlIjoib2JqZWN0IiwicHJvcGVydGllcyI6eyJ1c2VySWQiOnsidHlwZSI6Im51bWJlciJ9LCJpZCI6eyJ0eXBlIjoibnVtYmVyIn0sInRpdGxlIjp7InR5cGUiOiJzdHJpbmcifSwiYm9keSI6eyJ0eXBlIjoic3RyaW5nIn19fX0=;Encoding=utf-8",
"subscriptionId": "604f52e1261a3c19104c0e25",
"connectionType": "JSON"
}
Where
name
— the name of the data source (will be displayed in the designer when selected).connectionString
— connection string, in the case of JSON, it consists of 3 items:Json
— a JSON file or a http/https link encoded in base64;JsonSchema
— a schema that describes the structure of a JSON file, encoded in base64;Encoding
— encoding, you should always passutf-8
.
subscriptionId
— the id of the workspace (subscription) to which a data source will be attached.connectionType
— connection type,JSON
is used in this guide.
Request example.
curl -X POST "https://https://fastreport.cloud/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\"}"
Response example.
{
"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
}