Last active
February 19, 2019 21:56
-
-
Save kmelve/687c729425439832ade18f02be1bcffd to your computer and use it in GitHub Desktop.
Write to Sanity from webtask.io/make
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Remember to add npm dependencies (click the 🔧) | |
| const SanityClient = require('@sanity/client'); | |
| const client = token => SanityClient({ | |
| projectId: '<YouProjectId>', | |
| dataset: 'production', | |
| useCdn: false, | |
| token | |
| }); | |
| module.exports = async function(context, cb) { | |
| const { created } = context.body.ids; | |
| // Remember to add the token to secrets (click the 🔧) | |
| const { SANITY_TOKEN } = context.secrets; | |
| const res = await created.reduce((trans, _id) => trans.patch(_id).setIfMissing({ | |
| title: 'Missing TITLE!!!' | |
| }), client(SANITY_TOKEN).transaction()).commit().catch(console.error) | |
| console.log(res) | |
| await cb(null, 200) | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment