I wanted to know whether it is possible to make POST request (with a json body) to external API in the enrichment step of Snowplow event tracking? I see the support for “enum”: [“GET”, “POST”, “PUT”] but in the repo I can only see that we can send a URI as a string. So is it possible to make POST call with a JSON body?
Yes - you can use POST with the API enrichment, the values you specify in inputs
will be converted into a JSON object that is sent with the request.
@mike So let’s say I define two values in inputs(“id” and “name”). So when making POST request what I should I pass in as params or the values specified in inputs is sent directly as a JSON object? And will those two fields be combined into one JSON object?
The inputs are an array of objects, where each object represents a key-value pair. You specify the keys (id
and name
in your example) and also where to get the values from: either the Snowplow enriched event pojo (for any atomic fields) or a json that represents a custom event or context.
In the api
section, you specify the method (POST
) and the URI that you want to make the call to. The inputs will then be automatically passed as a JSON payload in a POST
request to that URI.
"parameters": {
"inputs": [
{
"key": "id",
"pojo": {
"field": "user_id"
}
},
{
"key": "name",
"json": {
"field": "contexts",
"schemaCriterion": "iglu:com.acme/user/jsonschema/1-*-*",
"jsonPath": "$.name"
}
}
],
"api": {
"http": {
"method": "POST",
"uri": "https://my_api_endpoint",
"timeout": 5000,
"authentication": {
"httpBasic": {
"username": "my_username",
"password": "my_password"
}
}
}
}
}