Monetization Policy

The Monetization policy allows you to track and monetize the usage of our API resources, declaratively and programatically.

Beta

This policy is in beta. You can use it today, but it may change in non-backward compatible ways before the final release.

Configuration

The configuration shows how to configure the policy in the 'policies.json' document.

{ "name": "my-monetization-inbound-policy", "policyType": "monetization-inbound", "handler": { "export": "MonetizationInboundPolicy", "module": "$import(@zuplo/runtime)", "options": { "allowRequestsOverQuota": false, "allowedSubscriptionStatuses": [ "active", "incomplete" ], "meterOnStatusCodes": "200-399", "meters": { "requests": 1 } } } }

Policy Configuration

  • name <string> - The name of your policy instance. This is used as a reference in your routes.
  • policyType <string> - The identifier of the policy. This is used by the Zuplo UI. Value should be monetization-inbound.
  • handler.export <string> - The name of the exported type. Value should be MonetizationInboundPolicy.
  • handler.module <string> - The module containing the policy. Value should be $import(@zuplo/runtime).
  • handler.options <object> - The options for this policy. See Policy Options below.

Policy Options

The options for this policy are specified below. All properties are optional unless specifically marked as required.

  • allowRequestsWithoutSubscription <boolean> -
    Indicates if requests without subscription should be allowed or not.
    Defaults to false.
  • allowedSubscriptionStatuses <string[]> -
    Indicates which subscription statuses should be allowed.
    Defaults to [["active","incomplete","trialing"]].
  • bucketId <string> -
    Indicates the bucket to be used, overrides the default one.
  • allowRequestsOverQuota <boolean> -
    Indicates if requests over quota should be allowed or not.
    Defaults to false.
  • meters <object> (Required) -
    The meters to be used by the policy against the subscription quota.
  • meterOnStatusCodes <string | number[]> -
    A list of successful status codes and ranges "200-299, 304" that should trigger a metering call.
    Defaults to "200-299".

Using the Policy

Read more about how policies work