•••
 
Documentation   /   Data Studio   /   Pulling data into documents
 
 

Pulling data into documents

 

[[INCLUDE=data]] pulls JSON data into a document, as variables. Use it to show live figures on a web page, fill a document with data from another system, or feed widgets.

[[INCLUDE=data({options}):{https_url}]]

The data source

The URL must start with https:// and return a JSON array of rows, each an object of key–value pairs:

[
  {"counterparty_name": "Acme Ltd", "contract_value": "12000"},
  {"counterparty_name": "Brightwork plc", "contract_value": "8500"}
]

A Plainly live data feed returns exactly this. See API: Live data feeds. The URL can contain variables.

The variables it creates

Each key in the data becomes a list variable, with one value per row:

Variable Value
{{prefix_key:0}}, {{prefix_key:1}}, ... The value from each row, starting at 0
{{prefix_key:count}} How many rows have a value
{{prefix_key:sum}} The total, if the values are numbers
{{prefix_key}} All the values, as a list. Use it in [[REPEAT]] blocks and widgets.

Options

Option Effect
prefix:{text} Put this in front of every variable name, so data from different sources doesn't clash.
save:true Save the values into the document, so they're kept and available to Data Studio. Otherwise they're only displayed.

Example

[[INCLUDE=data(prefix:renewals_):https://plainly.com/query-json?h={dataset_id}&key={dataset_key}&filter=end_date%20after%20{{*today}}]]

<h2>Current contracts</h2>
<p>{{renewals_counterparty_name:count}} contracts are still running.</p>
[[INCLUDE=widget(type:table,columns:renewals_counterparty_name|renewals_end_date,column_headings:Supplier|Ends)]]

Refreshing

Data is fetched when the document is opened, and again at most every 15 minutes. Documents with a final signed version don't refresh.

Data from another Plainly document

[[INCLUDE=document_data:{document_key}]] brings in all the variables from another Plainly document, without showing it. To show the whole document as well, use [[INCLUDE=document:{document_key}]].