Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

An experimental tool to update GOV.UK Publishing API via Contentful Webhooks

License

Notifications You must be signed in to change notification settings

alphagov/contentful-listener-api

Repository files navigation

Contenful Listener API

⚠️ This application is experimental 🪄 and is not currently a part of the GOV.UK stack

An application that keeps content managed in a Contentful CMS instance in-sync with the GOV.UK Publishing API. It listens for Contentful webhooks that affect individual content items and updates GOV.UK content accordingly. It is intended to be used for bespoke pages on GOV.UK which are not handled by the internal GOV.UK CMS tools.

Technical documentation

This application is built using the Sinatra microframework for Ruby HTTP applications.

This application is not currently configured with GOV.UK Docker and thus should be run on your host machine using rbenv.

Running the test suite

bundle exec rake

Running the app with Contentful

To use this application locally with a Contentful instance you will need to do some additional configuration both locally and in Contentful. You will also need a running instance of Publishing API (govuk-docker up publishing-api-app-lite).

In Contentful you need to create API access tokens for the spaces you need to access (see access_tokens configuration for the space ids and environment variable names). You should scope the access token to a sandbox environment you have created to avoid changing any of the live content.

In order for your application instance to receive Contentful webhooks, you will need to use software to expose the application to the public internet. Ngrok is a good option.

You can then start the application with:

$ CONTENTFUL_ENVIRONMENT=<environment name> \
<environment variable prefix for your space>_DRAFT_ACCESS_TOKEN=<draft access token> \
<envrionment variable prefix for your space>_LIVE_ACCESS_TOKEN=<live access token> \
bundle exec puma

and expose it to the public internet with $ ngrok http 9292. This will output a forwarding URL.

To complete the set-up you need to create a webhook in Contentful and point it to send POST requests to the /listener path of your forwarding URL.

When you make changes in the Contentful UI you should see webhooks being received by the application. You can see a log of the attempts to call the endpoint in the Contentful web interface with the webhook settings.

Once you have completed your development session, you should go into the Contentful web interface and delete your webhook, your sandbox environment and your access token.

Further documentation

Licence

MIT License

About

An experimental tool to update GOV.UK Publishing API via Contentful Webhooks

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks