Contexts in webhook POST request?

Everything is setup and working great now, but I can’t figure out how to add contexts to my event requests to the collector.

I’m just using webhooks/POST requests manually for now.

My example POST request looks like:

POST https://my-domain.com/com.snowplowanalytics.iglu/v1
{ "schema":"iglu:com.my-domain/event/jsonschema/1-0-0", "data": { "category": "test", "action": "test action" } }

Which all works. Though I’m confused how to add contexts to a request like this.

Tried a variety of “cx” and “co” values in JSON and querystring, base64 encoded and not. Also tried schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0' with “data” key as an array of nested objects with schema/data pairs as well. Nothing I’ve tried seems to work.

Is there any documentation on it? I’ve been searching everywhere. Even looking at the source code of the JavaScript Tracker.

What environment are you executing this in? Generally you’ll want to be using either the /i or /tp2 endpoint (for GET and POST respectively) rather than the endpoint above which is more specifically for webhooks and things that are adapted to Iglu.

If you are using a tracker of course this becomes quite a bit easier as it’s done under the hood for you, otherwise the best source of documentation for figuring out parameters is the tracker protocol - https://github.com/snowplow/snowplow/wiki/snowplow-tracker-protocol

What do you mean by environment? It can be local, on my development environment, doesn’t matter.

I’m using the scala-collector. I’ve been referencing that wiki page, even trying some of the request parameters from it’s examples, but I can’t find the magic combination.

I’m sure I’ll use an actual tracker library in my code when I go to implement, but I just want to make calls from Postman/Insomnia and test things out.

I’m now making a POST request to http://my-domain/com.snowplowanalytics.iglu/tp2 and trying to send JSON body with:

{
  "schema": "iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",
  "data": [
    { ... },
    { ... }
  ]
}

Where data includes nested schema/data objects. As defined here: https://github.com/snowplow/snowplow/wiki/snowplow-tracker-protocol#4-custom-contexts

Still not working unfortunately. Are there any complete examples? I think something is lost in translation with each piece of the request section by section maybe.

Thanks!

@Tom_M, Mike’s question of the environment is legitimate. If you are in control of the environment than you need to change the collector endpoint as Iglu webhooks do not allow capturing contexts.

Here’s an example of how you can send a custom event with some contexts to /com.snowplowanalytics.snowplow/tp2 (POST endpoint):

curl --request POST \
  --url http://<COLLECTOR_URI>/com.snowplowanalytics.snowplow/tp2 \
  --header 'content-type: application/json' \
  --data '{
  "schema": "iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4",
  "data": [
    {
      "e": "ue",
      "tv": "curl",
      "p": "web",
      "ue_pr": "{\"schema\":\"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0\",\"data\":{\"schema\":\"<CUSTOM_EVENT_SHEMA>\",\"data\":{\"<CUSTOM_EVENT_DATA\"}}\",
      "co": "{\"schema\":\"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0\",\"data\":[{\"schema\":\"<CUSTOM_CONTEXT_SHEMA>\",\"data\":{\"<CUSTOM_CONTEXT_DATA\"}}]}"
    }
  ]
}'
3 Likes

Thanks for the example. I used ue_px and cx since base64 encoding was easier with the Insomnia REST tool I’m using. Messages still ended up in the bad topic though. I’ll keep trying various combinations with the proper endpoint now though.

@Tom_M, great! I assume the issue is rather with either how you composed your data in the request or the validation of that data against the corresponding JSON schema. Let us know if you need any help to figure out why your event ended up in bad queue.

I also use Insomnia and just extracted curl from it to demonstrate. I picked up an unencoded example for visibility too. Using base64 encoded data is a prefered method.

Thanks, I appreciate it. I just used one of the clients and seems to work. I’d love to figure out how to put together a test request from a tool, but I’ll work backwards from the code so to speak.