Gatsby: How do you update your Gatsby site that's hosted on Heroku when a new Wordpress blog is published

Created on 30 Jun 2020  路  6Comments  路  Source: gatsbyjs/gatsby

Summary

Hello! So I'm a newby in Gatsby but have a fair understanding on programming (HTML, CSS etc). But I've managed to integrate a Wordpress blog to a Gatsby site using all the tutorials online. The part I'm stuck at is how to update the site when a new post is published whilst using Heroku. I've seen that most people seem to be using Netlify to host their site and I'm not sure how to apply the same principles on Heroku.

Any advice or help would be greatly appreciated. Thank you :)

Relevant information

The Wordpress site is hosted on Wordpress.com, not locally. I don't know if that changes anything.

Environment (if relevant)

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

help wanted stale? WordPress question or discussion

Most helpful comment

If I'm not mistaken, the Heroku webhooks API @graysonhicks linked to is for configuring webhooks to be sent _out_ of Heroku when things happen in the Heroku environment.

I believe what would be needed is to make use of the Heroku Platform API to make a build request: https://devcenter.heroku.com/articles/platform-api-reference

You could use the WordPress webhook functionality to send a webhook from WordPress to Heroku when content in WordPress changes, but I believe the destination the WordPress webhook needs to post to would need to be to a Heroku Platform API endpoint.

I'm not familiar enough with the Heroku APIs to give expert advice here, but this article looks promising: https://devcenter.heroku.com/articles/build-and-release-using-the-api

All 6 comments

I haven't used Heroku in a bit, but it looks like they have a webhooks API here. Wordpress also has webhook functionality here.

You will need to configure your Wordpress to trigger your Heroku webhook when content is published.

Maybe someone with specific experience in these two tools can give you more detailed instructions.

If I'm not mistaken, the Heroku webhooks API @graysonhicks linked to is for configuring webhooks to be sent _out_ of Heroku when things happen in the Heroku environment.

I believe what would be needed is to make use of the Heroku Platform API to make a build request: https://devcenter.heroku.com/articles/platform-api-reference

You could use the WordPress webhook functionality to send a webhook from WordPress to Heroku when content in WordPress changes, but I believe the destination the WordPress webhook needs to post to would need to be to a Heroku Platform API endpoint.

I'm not familiar enough with the Heroku APIs to give expert advice here, but this article looks promising: https://devcenter.heroku.com/articles/build-and-release-using-the-api

@mumbii Have you had any luck with the approach described by @jasonbahl ?

I have a Gatsby app on Heroku with webhook triggered builds. We are using Contentful but the integration should be more or less the same. On a publish event you'll want to hit Heroku's build endpoint with a POST request.

We also trigger a nightly build using the following config with axios, here you can see the endpoint, headers and data payload you need to send from your webhook.

const axiosOptions = {
  url: 'https://api.heroku.com/apps/<HEROKU_APP_NAME>/builds',
  method: 'POST',
  headers: {
    Accept: 'application/vnd.heroku+json; version=3',
    Authorization: `Bearer <HEROKU_AUTH_TOKEN>`,
    'Content-Type': 'application/json',
  },
  data: {
    source_blob: {
      url: `https://<GITHUB_AUTH_USERNAME>:<GITHUB_AUTH_API_KEY>@github.com/<GITHUB_USERNAME>/<GITHUB_REPOSITORY_NAME>/archive/master.tar.gz`,
    },
  },
}

Hiya!

This issue has gone quiet. Spooky quiet. 馃懟

We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 馃挭馃挏

Hey again!

It鈥檚 been 30 days since anything happened on this issue, so our friendly neighborhood robot (that鈥檚 me!) is going to close it.
Please keep in mind that I鈥檓 only a robot, so if I鈥檝e closed this issue in error, I鈥檓 HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 馃挭馃挏

Was this page helpful?
0 / 5 - 0 ratings