Webhooks

View as Markdown

Webhooks

A webhook is a mechanism that sends real-time information to any third-party app or service to keep your application in sync with your Contentstack account. Webhooks allow you to specify a URL to which you would like Contentstack to post data when an event happens.

create

The create method creates a new webhook in a specific stack.

NameTypeDescription
data (required)Dict

Data required to create a new webhook

data = {

"webhook":{

               "name":"Test",

               "destinations":[

               {

                   "target_url":"http://example.com",

                   "http_basic_auth":"basic",

                   "http_basic_password":"test",

                   "custom_header":[

                   {

                       "header_name":"Custom",

                       "value":"testing"

                   }

                   ]

               }

               ],

               "notifiers": "[email protected]",

               "channels":[

               "assets.create"

               ],

               "branches":[

               "main"

               ],

               "retry_policy":"manual",

               "disabled":false,

               "concise_payload":true

           }

           }

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

response = client.stack('api_key').webhooks().create(data).json()

delete

The delete method removes an existing webhook from the stack permanently.

NameTypeDescription
webhook_uid (required)str

UID of the webhook

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

response = response = client.stack('api_key').webhooks('webhook_uid').delete().json()

executions

The execution method retrieves the execution details of a specific webhook, which includes the execution UID.

NameTypeDescription
webhook_execution_uid (required)str

UID of the webhook execution

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

response = client.stack('api_key').webhooks('webhook_execution_uid').executions().json()

export

The export method exports an existing webhook to a downloadable JSON file.

NameTypeDescription
webhook_uid (required)str

UID of the webhook

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

response = client.stack('api_key').webhooks('webhook_uid').export().json()

fetch

The fetch method retrieves the details of a specific webhook.

NameTypeDescription
webhook_uid (required)str

UID of the webhook

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

response = client.stack('api_key').webhooks('webhook_uid').fetch().json()

find

The find method retrieves the details of all the webhooks available in the stack.

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

response = client.stack("api_key").webhooks().find().json()

import

The import method imports an existing webhook by uploading a JSON file.

NameTypeDescription
file_path (required)str

The path of the file to be uploaded

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

file_path = "tests/resources/mock_content_types/import_content_types.json"

response = client.stack('api_key').webhooks().imports(file_path).json()

logs

The logs method retrieves the latest execution log of the webhooks.

NameTypeDescription
execution_uid (required)str

UID of the execution

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

response = client.stack('api_key').webhooks().logs('execution_uid').json()

retry

The retry method makes a manual attempt to execute a webhook after the automatic attempts are exhausted.

NameTypeDescription
execution_uid (required)str

UID of the execution

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

response = client.stack('api_key').webhooks().retry('execution_uid').json()

update

The update method allows you to update the details of an existing webhook in the stack.

NameTypeDescription
data (required)Dict

The updated data of the webhook

data = {

        "webhook":{

            "name":"Updated webhook",

            "destinations":[

            {

                "target_url":"http://example.com",

                "http_basic_auth":"basic",

                "http_basic_password":"test",

                "custom_header":[

                {

                    "header_name":"Custom",

                    "value":"testing"

                }

                ]

            }

            ],

            "channels":[

            "assets.create"

            ],

            "branches":[

            "main"

            ],

            "retry_policy":"manual",

            "disabled":true,

            "concise_payload":true

        }

        }

import contentstack_management 

client = contentstack_management.Client(host='host_name')

client.login(email="email_id", password="password")

response = client.stack('api_key').webhooks('webhook_uid').update(data).json()