Skip to content

Instantly share code, notes, and snippets.

@stefanoverna
Created June 6, 2018 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanoverna/09fa06630f9193381040512b5fddccb0 to your computer and use it in GitHub Desktop.
Save stefanoverna/09fa06630f9193381040512b5fddccb0 to your computer and use it in GitHub Desktop.
const { SiteClient } = require('datocms-client');
const client = new SiteClient('YOUR-API-TOKEN');
const config = require('./gatsby-config');
config.siteMetadata.products.reduce((chain, product) => (
chain
.then(() => client.uploadImage(product.image))
.then((image) => client.items.create({
name: product.name,
image: image,
price: product.price,
itemType: 'YOUR-MODEL-ID',
}))
), Promise.resolve());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment