Send data with a key
When your data already lives somewhere else, such as a spreadsheet, a database or a list your team keeps, a script or an automation tool can send it to your website with its data key. It goes online by itself as Automatic data publishing explains, with the same checks. No AI sits in between, so the data goes exactly where you say.
Before you start
Section titled “Before you start”- Turn on Automatic data publishing for the website. The key works only while it is on.
- Under Data key, press Make a key, then Copy the key. It starts with
dk_and is shown only this once. - Keep it like a password: whoever holds it can send data to that website. Put it in your tool’s place for secrets, never in a page or a shared file.
Make a new key or Revoke ends the current key at once. Turning Automatic data publishing off, or handing the website over to another account, ends it too; a pause keeps it. Only the account’s holder makes or revokes it. A website has one key at a time.
What your website takes
Section titled “What your website takes”Ask first what your website takes, with the key and nothing else:
curl -s https://api.tsurito.com/v1/data -H "Authorization: Bearer dk_your_key"
The answer lists what can be sent by itself, as it is online now:
sections: each section with data, bypage, its place on the page (section, counted from 0), itstypeand itsfields, with the values they have now.settings: the announcement bar and the contact details, such ascontact.phone.newPages: the kinds of page you can add, such as a news item: thefolderthey go in, and inlinkedFromthe list sections that link to them.stateandlastRun: whether Automatic data publishing is on, and what happened the last time data came.
It answers only while the website is online. Read it again after you change the website’s sections in Studio or the Panel: the places may have moved.
What you send
Section titled “What you send”Send the data with POST to the same address, as JSON. Name each section by its page, place and type, as the answer above shows them, and give only the fields that change:
{
"sections": [
{
"page": "home",
"section": 2,
"type": "menu",
"fields": {
"heading": "Today's menu",
"groups": [
{
"title": "Today",
"items": [
{ "title": "Escudella", "body": "Winter soup with pasta and meatballs", "price": "€9" },
{ "title": "Crema catalana", "body": "Burnt to order", "price": "€6" }
]
}
]
}
}
],
"settings": {
"announcement": { "message": "Open on Monday, the 8th" }
}
}
- A field you send takes the place of what is there. A list, such as
groupsoritems, is sent whole: the new list replaces the old one, so to add a dish, send the list with the dish in it. nullempties a field.settingstakes the same names as the answer above, nested:contact.phoneis sent as{ "contact": { "phone": "…" } }.- To add a page of a kind the website already has, send it in
newPages, with itsnameinside that kind’sfolder, such asnews/new-opening-hours, itstitleand thesectionsof that kind of page. In the same send, add a link to it in the list thatlinkedFromnames, by sending that list whole with the new item. A new page that no list links to is refused, and nothing is written. At most 10 a time. - If the page, the place or the type does not match, nothing is written and the answer says what is there now.
- If what you send would change more than data, such as the design or the order of the sections, nothing is written. Make that change yourself, in Studio or the Panel.
The answer
Section titled “The answer”When something was done, the answer is JSON with an outcome and a message that says what happened:
published(status 200): it is online, as the version the answer names.will_publish(status 202): it holds only data and the new version is being built; it goes online by itself in a few minutes, after the same checks. There is nothing more to send.nothing_new(status 200): what you sent is already online. Nothing was built.waits(status 409): it went into the draft but waits for you, such as when the draft also holds a change of design, more than 10 new pages, or a page that looks worse than online.waitingsays why andpublishUrlopens the draft to publish it yourself.
When nothing went online by itself, the answer is an error, with a status of 400 or more and error.code, error.message and, in error.details.reason, why. When you can publish the draft yourself, such as when it was changed by hand in the Panel, error.details.publishUrl opens it. Some errors, such as a draft changed by hand or having used the day’s 4 automatic publishes, keep the data you sent in the draft. The cases are in When nothing goes online by itself.
Some tools take any status of 400 or more as a failure. A 409 with an outcome of waits is not one: the data is in the draft, waiting for you.
The website’s page in the Panel shows each time data came, and we email you when something could not go online, as for an assistant.
Limits
Section titled “Limits”- The website goes online by itself at most 4 times a day, however the data comes.
- Each key can be used a limited number of times an hour. When it is reached, the error’s code is
rate_limitedand itsRetry-Afterheader says how many seconds to wait. - Send only when the data changes. Sending the same data again, once it is online, answers
nothing_newand still counts as a use of the key.
Examples
Section titled “Examples”Each example sends the menu above. Change dk_your_key, the page, the place, the type and the fields to your website’s, from what it takes. We wrote the steps from each tool’s own help, and their menus change from time to time.
A script, with curl
Section titled “A script, with curl”On a Mac or Linux, put the data in a file, data.json, and send it:
curl -s -X POST https://api.tsurito.com/v1/data \
-H "Authorization: Bearer $TSURITO_DATA_KEY" \
-H "Content-Type: application/json" \
--data @data.json
Keep the key in the variable TSURITO_DATA_KEY rather than in the script. To send it every day, schedule the script with your computer’s own way, such as cron.
PowerShell, on Windows
Section titled “PowerShell, on Windows”PowerShell comes with Windows. Save this as send-data.ps1, beside data.json:
$headers = @{ Authorization = "Bearer $env:TSURITO_DATA_KEY" }
$body = Get-Content -Raw -Encoding UTF8 "$PSScriptRoot\data.json"
try {
$answer = Invoke-RestMethod -Method Post -Uri "https://api.tsurito.com/v1/data" -Headers $headers -ContentType "application/json; charset=utf-8" -Body ([System.Text.Encoding]::UTF8.GetBytes($body))
$answer.outcome
} catch {
$_.ErrorDetails.Message
}
To run it every day, open Task Scheduler, choose Create Basic Task, pick the time, and as the action start powershell.exe with -File and the path of send-data.ps1. At work, your IT may need to allow scripts, or calls to the internet, first.
Power Automate
Section titled “Power Automate”In a flow with a schedule (Scheduled cloud flow), add the HTTP action:
- Method:
POST. - URI:
https://api.tsurito.com/v1/data. - Headers:
AuthorizationwithBearerand your key, andContent-Typewithapplication/json. - Body: the JSON, with your data in it from the flow’s earlier steps, such as the rows of an Excel table.
The flow marks the step as failed on a status of 400 or more; read the step’s output to see whether it is waits. The HTTP action is a premium action of Power Automate, and in an organisation its IT can block it. If it is blocked, PowerShell above does the same.
Zapier
Section titled “Zapier”Add the step Webhooks by Zapier, with the event Custom Request: method POST, the address https://api.tsurito.com/v1/data, the JSON in Data, and in Headers Authorization with Bearer and your key and Content-Type with application/json. The step before it brings the data, such as a new row in a spreadsheet.
Add the HTTP module Make a request: the address https://api.tsurito.com/v1/data, the method POST, the header Authorization with Bearer and your key, the body type Raw, the content type JSON, and the JSON as the request content.
Add an HTTP Request node: method POST, the address https://api.tsurito.com/v1/data, a header Authorization with Bearer and your key, and Send Body on, as JSON. Start it with a Schedule Trigger, or after the node that reads your data.
Apple Shortcuts
Section titled “Apple Shortcuts”On an iPhone, iPad or Mac, add Get Contents of URL with the address https://api.tsurito.com/v1/data. Under its options, set Method to POST, add the header Authorization with Bearer and your key, and set Request Body to JSON with the fields to send. To run it by itself, make an automation in Shortcuts at the time you choose.