Sending API transaction metadata to Revenium Metering Beacons is configured on Azure API Management using Inbound and Outbound processing policies. To configure these navigate to the Policy configuration for the API you want to monetize as follows:
Click on the code editor to enter the XML policy configuration:
Add the following XML configuration and replace the following values:
REVENIUM_METERING_BEACON_KEY
The Metering Beacon API Key provided by the Revenium Team
REVENIUM_ASSET_ID
The Sources ID Obtained from the Revenium Application
<policies>
<inbound>
<base />
<send-one-way-request mode="new">
<set-url>https://api.revenium.io/meter/v1/api/event</set-url>
<set-method>POST</set-method>
<set-header name="x-api-key" exists-action="override">
<value>API_KEY_GOES_HERE</value>
</set-header>
<set-header name="content-type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>@{
return new JObject(
new JProperty("requestId",context.RequestId),
new JProperty("assetId","ASSET_ID_GOES_HERE"),
new JProperty("eventType", "REQUEST"),
new JProperty("url", context.Api.Path),
new JProperty("productKey", context.Request.Headers.GetValueOrDefault("x-revenium-product-key","")),
new JProperty("method", context.Request.Method),
new JProperty("currentMillis", (new DateTimeOffset(DateTime.Now)).ToUnixTimeSeconds() * 1000 )
).ToString();
}</set-body>
</send-one-way-request>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
<send-one-way-request mode="new">
<set-url>https://api.revenium.io/meter/v1/api/event</set-url>
<set-method>POST</set-method>
<set-header name="x-api-key" exists-action="override">
<value>API_KEY_GOES_HERE</value>
</set-header>
<set-header name="content-type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>@{
return new JObject(
new JProperty("requestId",context.RequestId),
new JProperty("assetId","ASSET_ID_GOES_HERE"),
new JProperty("eventType", "RESPONSE"),
new JProperty("responseCode", context.Response.StatusCode),
new JProperty("currentMillis", (new DateTimeOffset(DateTime.Now)).ToUnixTimeSeconds() * 1000 )
).ToString();
}</set-body>
</send-one-way-request>
</outbound>
<on-error>
<base />
</on-error>
</policies>
The Revenium Source ID can be obtained from the Sources page: