Create New WebHook to get Notified when new Blog is created

Hello @roger ,

I am thinking & planning to Create & Setup the Webhook from the Project Setting for the Record Entity with Create as an Event.

I need to create a Webhook in which I need to add or get some specific data like Blog Title, Blog Slug, Blog Written On I need all this information in the Webhook body/payload, @roger can you please help me with this and setup the Webhook with required information.

Hi @dhavalveera1,

Sure thing. I made an example webhook in that example project from your other email. Please check the webhooks section in that demo environment.

Its setup is very simple:
Screenshot 000156

You can specify any webhook URL you want, and leave the HTTP body settings the default.

When that webhook fires, the default body looks like the below JSON, and includes those fields. Specifically, entity.blog_title, entity.blog_slug, and entity.blog_written_on should be the details you need. You can of course name those fields whatever you want.

{
  "environment": "datocms-support-main-copy-08-16-2024",
  "entity_type": "item",
  "event_type": "create",
  "entity": {
    "id": "example_id",
    "type": "item",
    "attributes": {
      "seo_details": {
        "image": "example_id",
        "title": "Webhook test",
        "no_index": false,
        "description": "Webhook test",
        "twitter_card": "summary"
      },
      "blog_title": "Webhook test (duplicate)",
      "blog_display_picture": {
        "alt": null,
        "title": null,
        "custom_data": {},
        "focal_point": null,
        "upload_id": "example_id"
      },
      "blog_description": {
        "schema": "dast",
        "document": {
          "type": "root",
          "children": [
            {
              "type": "paragraph",
              "children": [
                {
                  "type": "span",
                  "value": "Webhook test"
                }
              ]
            }
          ]
        }
      },
      "blog_category": "Webhook test",
      "blog_written_on": "2024-08-16",
      "blog_tags": "test",
      "blog_slug": "webhook-test"
    },
    "relationships": {
      "item_type": {
        "data": {
          "id": "example_id",
          "type": "item_type"
        }
      },
      "creator": {
        "data": {
          "id": "125172",
          "type": "account"
        }
      }
    },
    "meta": {
      "created_at": "2024-08-16T20:18:48.616+01:00",
      "updated_at": "2024-08-16T20:18:48.623+01:00",
      "published_at": "2024-08-16T20:18:48.663+01:00",
      "publication_scheduled_at": null,
      "unpublishing_scheduled_at": null,
      "first_published_at": "2024-08-16T20:18:48.663+01:00",
      "is_valid": true,
      "is_current_version_valid": true,
      "is_published_version_valid": true,
      "status": "published",
      "current_version": "example_id",
      "stage": null
    }
  },
  "related_entities": [
    {
      "id": "example_id",
      "type": "item_type",
      "attributes": {
        "name": "Blog",
        "singleton": false,
        "sortable": false,
        "api_key": "blog",
        "ordering_direction": null,
        "ordering_meta": null,
        "tree": false,
        "modular_block": false,
        "draft_mode_active": false,
        "all_locales_required": false,
        "collection_appearance": "table",
        "has_singleton_item": false,
        "hint": null,
        "inverse_relationships_enabled": false
      },
      "relationships": {
        "fields": {
          "data": [
            {
              "id": "example_id",
              "type": "field"
            },
            {
              "id": "example_id",
              "type": "field"
            },
            {
              "id": "example_id",
              "type": "field"
            },
            {
              "id": "example_id",
              "type": "field"
            },
            {
              "id": "example_id",
              "type": "field"
            },
            {
              "id": "example_id",
              "type": "field"
            },
            {
              "id": "example_id",
              "type": "field"
            },
            {
              "id": "example_id",
              "type": "field"
            }
          ]
        },
        "fieldsets": {
          "data": []
        },
        "singleton_item": {
          "data": null
        },
        "ordering_field": {
          "data": null
        },
        "title_field": {
          "data": {
            "id": "example_id",
            "type": "field"
          }
        },
        "image_preview_field": {
          "data": {
            "id": "example_id",
            "type": "field"
          }
        },
        "excerpt_field": {
          "data": null
        },
        "workflow": {
          "data": null
        }
      },
      "meta": {
        "has_singleton_item": false
      }
    }
  ]
}

Hope that helps!

Hi @roger ,

Thanks for helping on this Webhook part.

I wanted to know that when the webhook is triggered, then does from my side do I need to return any kind of response? like Success Response with 200 Status Code or anything?

That would be a best practice, and it would allow you to easily see (inside Datoโ€™s project settings, at /project_settings/webhook_calls) which of your webhooks succeeded (20x) or failed (probably 40x or 50x, depending on how it failed).

But thatโ€™s just for your own information. Once you get the webhook from us, itโ€™s really up to your system to process it however you see fit. What you return to us is purely informational.