Contentful: Prevent webhook from triggering, when using Content Management API

混江龙づ霸主 提交于 2019-12-12 17:16:12

问题


So I've created a webhook within the Contentful dashboard, that triggers when an entry is either published or deleted, and it works as it should. However, I want to be able to publish entries via the Content Management JavaScript API, without triggering the webhook. Are there any measures I can take to make this possible?


回答1:


Unfortunately there's no difference if an entry is published through the API or the web app directly. The web app simply calls the API under the hood.

What might be possible is to inspect the published entry within the web hook and evaluate whether code should execute or not. Perhaps by setting a hidden field when publishing through the API directly.

For example say you have a field publishedThroughAPI, you make sure this field is omitted from the delivery API and not editable:

Then set this field to true just before publishing through the JavaScript API and inspect this field in your webhook and simply return out of the hook if the field is set to true.

The webhook will recieve a payload that contains your published entry. Basically the same payload as for a normal request with the difference that it will contain every locale. Below is a small example:

{
   "sys": {
         //System meta data, created at, published at etc.
    },
   "fields": {
       //All fields of the entry.
       "title": {
            "en-US": "English title",
            "sv-SE": "Swedish title"
       },
       "publishedThroughAPI": {
            "en-US": true,
            "sv-SE": true
       }
   }
}


来源:https://stackoverflow.com/questions/44380971/contentful-prevent-webhook-from-triggering-when-using-content-management-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!