Skip to content

Instantly share code, notes, and snippets.

@kmelve
Last active February 19, 2019 21:56
Show Gist options
  • Select an option

  • Save kmelve/687c729425439832ade18f02be1bcffd to your computer and use it in GitHub Desktop.

Select an option

Save kmelve/687c729425439832ade18f02be1bcffd to your computer and use it in GitHub Desktop.
Write to Sanity from webtask.io/make
// 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