How to use data sources

Store and fetch data from data sources in Create

This guide shows you how to create a data source to store data, and then use the stored data in a recipe. An example dataset, data transformation and template are provided, but you can also follow along with your own data.

Prerequisites

Procedure

The process consists of the following tasks:

  • Set up a data source.
  • Set up a recipe or open an existing one.
  • Inside the recipe, fetch data from the data source.

Set up a data source

We start by creating a data source:

  1. Obtain a JSON array of objects that holds some data for a data source. If you don't have one, use the following dataset.
[
  {
    "OfficeName": "Copenhagen",
    "City": "Copenhagen",
    "Country": "Denmark",
    "Address": "Wilders Plads 15A",
    "__id": "0"
  },
  {
    "OfficeName": "New York",
    "City": "New York",
    "Country": "USA",
    "Address": "One World Trade Center, 48th Floor",
    "__id": "1"
  }
]
  1. Copy the array.
  2. Navigate to Data sources in your unit.
  3. Create a new data source, and name it Offices, or whatever is a relevant name for your data source.
  4. Navigate to the JSON view.
  5. Paste the array into the data source.
  6. Select Save.
The table view of the data source. Each object represents a row, and each of its properties a column.

The table view of the data source. Each object represents a row, and each of its properties a column.

Our data source is now created.

Use data from a data source

In the next steps, fetch data from the data source from inside a recipe.

  1. Open an existing recipe or create a new one at a location of your choice.
  2. If you don't already have a template, you can use this one.
  3. Navigate to the Data tab.
  4. If you don't have your own data set, select the Edit icon, add the following to the Sample data, and hit Update:
{
  "office":"Copenhagen"
}
  1. Add the following to the Data transformation:
{
  dkOffice: datasource('Offices', 'OfficeName', office)
}

If using your own data, the syntax can be found here. The first argument is data source name, the second is the data source column, and the third one is the value to look up. The entire object/row is returned.

  1. Select Transform on the right side of the top Navigation bar.
  2. The data should be transformed, yielding the following result in the Transformation result pane:
{
  "dkOffice": {
    "OfficeName": "Copenhagen",
    "City": "Copenhagen",
    "Country": "Denmark",
    "Address": "Wilders Pl. 15A",
    "__id": "0"
  }
}

The data is now ready to be used in a template.

Conclusion

You just saved data to make it available to all recipes in a unit as a data source. You then fetched data from the data source based on a piece of information that the recipe received, and made the fetched data available to be used in a template.