简体   繁体   中英

How to input data into datoCMS with api based off of data added to stripe product

I have a Gatsby Website that is setup with DatoCMS, so when a change is made in datoCMS and built, it triggers a netlify build and updates all the content. I am also using the stripe source gatsby plugin to pull in products in graphQL and rebuild the site on netlify when those products, are updated via a netlify webhook triggered by stripe product update.

I'd also like the stripe products to live in datoCMS, so I can add more details pictures, text so ideally, instead of using the gatsby tripe source plugin to pull in data from stripe. I would somehow have stripe populate fields in datoCMS. They have a content managment API, where I could write a function to upload say a image like so

client.uploadFile('http://i.giphy.com/NXOF5rlaSXdAc.gif')
  .then((image) => {
    return client.items.create({
      itemType: '7149',
      title: 'My first article!',
      content: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod.',
      coverImage: image
    })
  })
  .then(record => console.log(record));

However I would have to run this function as a netlify function at build time from the webhook being triggered by stripe with a new product, then somehow trigger this function, witht the correct stripe product infro, send it to DatoCMS, then once I am done editing on dato it should be able to add my other content to the same model that it generated.

Basically my question is. Is there a way to trigger a netlify function to fire once the stripe source plugin for gatsby has pulled down the latest data at build and pass that data into the function to send to dato? Also how would I test this in development, because the webhook is for the netlify site build, can I create a webhook for localtesting for stripe to trigger?

Let me know if you need more explanation?

I'm not sure about Netlify build triggers, but you can use Stripe CLI to help with local Stripe webhook testing .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM