I'm seeing something odd when we send data into ru...
# support
t
I'm seeing something odd when we send data into rudderstack via a webhook source. It looks like when you send event track call this way, rudderstack is then wrapping it within another layer of an event. If my payload sent to rudderstack is this:
Copy code
{
  "type": "track",
  "event": "Upgrade CTA [Discounts] Clicked",
  "originalTimestamp": "2024-01-08 23:16:51.589000",
  "userId": "5476",
  "request_ip": "24.143.104.2",
  "context": {
    "traits": {
      "email": "test@bigcartel.com"
    }
  }
}
Looking at what the rudderstack Live Events view shows me from the webhook source is this.
Copy code
{
  "anonymousId": "38215463-e99f-4d2f-bec5-46e954dcea9f",
  "event": "webhook_source_event",
  "messageId": "7779a9ec-6635-4392-adf3-df6fd93cb976",
  "properties": {
    "event": "Upgrade CTA [Bulk Editing] Clicked",
    "originalTimestamp": "2024-01-09 00:20:56.236000",
    "request_ip": "71.212.158.50",
    "traits": {
      "email": "test@bigcartel.com"
    },
    "type": "track",
    "userId": "5476"
  },
  "rudderId": "28b43a9c-d1b5-4385-b156-db1bdbe5144d",
  "type": "track"
}
Notice that my original event is within the
properties
and there is an outer event called
webhook_source_event
. Thihs makes webhook events behave differently than other SDK sources which doesn't do this. This has ramifications with how to easily reuse transformations for a single destination that may say get events from a webhook source vs javascript source. E.g. you cannot just look for
event.context.traits
. You have to see if it's a webhook source event, then look at
event.properties.context.traits
What the heck? For downstream destinations, it seems I now how have these differently than other events to "unwrap" the webhook events because Rudderstack isn't automatically handling this. For example looking at the event send to Klaviyo the payload looks like this. Notice the event is
webhook_source_event
instead of my actual event. This is a huge fail IMO. Webhook events should be handled exactly the same as other events from other SDKs. This forced us to now special case webhook events to deal with this and manually construct the real event payload that RS shoudl be doing automatically
Copy code
{
  "version": "1",
  "type": "REST",
  "method": "POST",
  "endpoint": "https://a.klaviyo.com/api/events",
  "headers": {
    "Authorization": "******e47c",
    "Content-Type": "application/json",
    "Accept": "application/json",
    "revision": "2023-02-22"
  },
  "params": {},
  "body": {
    "JSON": {
      "data": {
        "type": "event",
        "attributes": {
          "metric": {
            "name": "webhook_source_event"
          },
          "properties": {
            "type": "track",
            "event": "Upgrade CTA [Bulk Editing] Clicked",
            "traits.email": "test@bigcartel.com",
            "userId": "5476",
            "request_ip": "71.212.158.50",
            "originalTimestamp": "2024-01-09 01:24:03.526000"
          },
          "profile": {
            "$id": "c1aeb07f-7697-402c-bc6a-9b472536b8ca"
          },
          "time": "2024-01-09T01:24:05.588Z"
        }
      }
    },
    "JSON_ARRAY": {},
    "XML": {},
    "FORM": {}
  },
  "files": {}
}
m
Hey There! 👋 Your message has been received by the RudderStack team. Our standard customer support hours are 9-6 PM EST, but we will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
Hey Trevin, yes this is correct, the webhook source is different from the others and I will try my best to get you an answer as to why this is the case.
t
@shy-kite-21035 It seems a bit crazy to me that this is the case, but if it is, it's also odd that RS doens't provide a transformation or some library to make this easier to unwrap it. I wrote this transformer but wanted to verify it is correct with your team:
Copy code
export function unwrapWebhookEvent(event) {
  if (event.event === 'webhook_source_event' && event.properties) {
    // Move all event properties to root level
    for (const key in event.properties) {
        event[key] = event.properties[key];
      }

      // Overwrite event name at the root level to be the actual event name
      event.event = event.properties.event;

      // Remove the 'properties' property as it's no longer needed
      delete event.properties;
  }

  return event;
}
It seems like everyone using webhook event sources would need this.
h
@thankful-gpu-70135, if your input data is already in the standard RudderStack event format, you can use an HTTP source instead of the webhook source. By convention, a generic webhook source is meant to ingest non-RudderStack standard events. Then, the user has to write a transformation on the destination to convert to the standard format. A source transformation would be the best choice, but we have yet to support it. Moreover, RudderStack supports the data format from all these "webhook" type sources and performs source transformation automatically, https://www.rudderstack.com/docs/sources/event-streams/cloud-apps/
t
@helpful-daybreak-79835 this is good info. I could not find this in the docs but may have missed it. Where are the docs for the HTTP source? Is it this: https://www.rudderstack.com/docs/api/http-api/ ?
h
You can add an HTTP source in the dashboard. Then, grab the write key and data plane URL to proceed with these docs.
t
Thanks. I’ll dig further. I’d recommend adding a pointer and recommendation to use the http api in the webhook docs. Unless someone really needs to use a webhook using the http api with standard event format is far far better
👍 1