To help you streamline content delivery to your application, we introduced WebHooks, which work as a trigger when an entry is changed to notify a service about the change that has happened.
You can create a webhook for your project by accessing the WebHook section.
The WebHooks can be used to automate the deployment of your static website when entries are being published or unpublished. Next, we'll cover a few examples of integrating the Decoupla WebHooks with some of the most popular CI/CD tools.
Integration with Github Actions
First, we would need to generate a Github API Token. To generate your new Personal access token, visit GitHub and open Settings > Developer settings. Then select “Generate new token”. If you use a fine-grained token, give it read and write access to Actions for the repository.
To trigger a Github Action, we would need to create a workflow dispatch event using the POST method on the https://api.github.com/repos/<OWNER>/<REPO>/actions/workflows/<WORKFLOW_ID>/dispatches URL.
Note: You can use the workflow filename as WORKFLOW_ID. The workflow also needs the workflow_dispatch trigger enabled.
We also need to specify an Authorization header for the WebHook using Authorization as the Header key and Bearer <GITHUB_TOKEN> as the header value.
GitHub also requires the X-GitHub-Api-Version header, we can use the value: 2022-11-28 to use the current version.
Github Actions require a content body to know which branch or tag to use for the action.
{
"ref": "branch or tag name",
"inputs": {}
}
The inputs object is optional and holds input values to be used in the workflow.
Integration with Gitlab Pipelines
First we would need a Pipeline trigger token. To generate one, go to your project Settings > CI/CD > Pipeline trigger tokens > Add new token.
To trigger the pipeline, we would use the POST method on https://gitlab.com/api/v4/projects/<PROJECT_ID>/ref/<REF_NAME>/trigger/pipeline?token=<TOKEN> URL.
Replace the PROJECT_ID with your project ID, and REF_NAME with your branch or tag you would want to use for the deployment, and the TOKEN with the token you generated.
We can leave the request body empty: {}.
Integration with Bitbucket Pipelines
Again, we would need a token. To generate one, go to your project > Repository Settings > Security > Access tokens > Create access token.
To trigger the pipeline we would use the POST method on https://api.bitbucket.org/2.0/repositories/<OWNER>/<PROJECT_SLUG>/pipelines/.
We would also need to add an Authorization header, create a new header in the WebHook with Authorization as the key and Bearer <TOKEN> as the value, and replace the <TOKEN> with your access token.
Bitbucket also requires a request body:
{
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "master"
}
}
Set ref_type to branch or tag, and ref_name to the name of your branch or tag.
Conclusion
Integrating Decoupla Webhooks with your deployment pipeline is a powerful way to automate your content updates and streamline your workflow.
