Setting up a Takeshape To Algolia Webhook
This post is about plumbing. Plumbing Takeshape.io content into Algolia via a Heroku microservice. Simply put, we are going to setup a Takeshape webhook that triggers when content is updated. The heroku endpoint the pushed the data to Algolia.
Security Note: You do not want to commit the API keys for either Takeshape or Algolia to your git repo, as this would be a huge security issue. Heroku config variables are the recommended solution.
Algolia API Key Setup
Log into your Algolia site get the App Id and Admin API Key. The Application Id is the first value in the API Keys section. The Admin API key needs to remain secure, so do not commit it to your code.
Take these two values and create two Heroku Config Variables: ALGOLIA_APPID and ALGOLIA_ADMIN_KEY.
Takeshape.io API Setup
The next step is to do the sample task in the Takeshape.io API settings. Create a new API key and store the API key in the TAKESHAPE_KEY variable. You can find the Takeshape Project Id in the Takeshape Url.
Setting up the Takeshape.io Webhooks
The final step is to add a takeshape webhook. You will need the Heroku App endpoint. Note the format: Heroku App URL + ‘/webhook’. Additionally you will need to select the content type you want to send to Algolia. In this case I have selected ‘Cheese’ and set the flags to trigger the webhook on Create, Update and Delete.
Configure your Heroku Takeshape Query
The final setup is to update the code in the git repo to use the data schema fields for your specific content type. You will need to edit the /heroku/routes/webhook.js file and take the fields and post them into the query. Not subtle, but it works.
When you edit the code paste your selected fields into the query.
Push to Heroku & Test
The final step is to commit your code and push the code to Heroku. If everything is working as expected, then you can see the webhook code run when you make changes to your data in Takeshape.
// use this to push your git repo to your heroku app
git push heroku// Use the following to monitor heroku logs
heroku logs -t
The final confirmation is to log into Algolia and check for a new objects in your index. The codebase assumes that your index will have the same name as the content type. This is done to minimize configuration and can help when you have more than one content type pushing to different indexes.