Create your own API for Craft Data Plugin (no code required)
Always copy pasting the same kind of information in your comps?
Let me show you how to improve drastically your workflow by creating your own API that can be used with Craft Data plugin, with no coding required at all.
By the way, API stands for Application Program Interface. It makes the communication possible between softwares. Your database and Sketch in this case.
The API will allow you to get the information from your Google Spreadsheet in your Sketch file super easily.
The only tools you need are:
Make sure to do the followings before starting:
- Install Sketch and Craft
- Create a Google account
- Create a Sheetsu account
The main steps we covered below are:
- Create a “database” in a Google Spreadsheet
- Create our API with Sheetsu
- Use it in Sketch with Data, a Craft plugin (and a bit of Duplicate)
1. Let’s fill in our “database”
In our case, I will use a list of 10 stores in San Francisco with information such as their name, address, opening hours, and distance. You can obviously make a database with any content you want. As long as you use the first column for “id” (unique identifier for each row) and the first row for column headers.
I could also have an “image” column with an image url for each store. The Data plugin works in the same way. The only different is that you would have to select a shape layer instead of a text layer to replace it.
Once done with your database, tap on the “Share” blue button and copy the link of the file.
2. From Spreadsheet to API
Go on Sheetsu.com and paste this link right where it says “Google Spreadsheet URL”. Then click on “CREATE API”.
Done! You now have a link to your API. You can even give it a name, if you get addicted to this tool and build many more APIs.
3. Plug your API with your design
Open now the Data plugin, and go to the JSON section. Here is the link to the Sketch file if you want to follow along.
Paste your API url and click on “Import”. All your database content should now be accessible.
Weird right? All these numbers. If you click on them you will see a specific row of your database. That’s how JSON works. By nesting data. This can be pretty powerful. I let you read the documentation on W3School.
Right below is an artboard I made for the purpose of this demo. You can see a template of store section with dummy data. I will now link the text layers with the information in the JSON file.
Here for instance, I selected the “store name” layer and then clicked on the “name” tag in the JSON.
Once all the text layers are linked to the values in the JSON. The magic can happen. If you open the Duplicate plugin, you can select how many instances of this template you want (10 in our case). 10 store sections should appear on your screen. With each of them a different set of values. Pretty cool right?
You made it! You created a very simple structured database, create an API to convert this information in a JSON file, and linked it to your comps.
Thank you for taking the time to read this post. I hope it will make you a better and faster designer, as it did for me.
Suggestions and/or questions most appreciated!