# IBM

APIs being proxied by IBM DataPower instances can be metered by Revenium using a simple GatewayScript configured in a Multi-Protocol Gateway Service as part of a Processing Policy.

## Setting up a TLS Client Profile

A TLS Client Profile must be configured for the GatewayScript to communicate with the Revenium Platform API. Start by navigating to Objects -> Crypto Configuration -> Configure TLS Client Profile and create a Client Profile called "revenium-metering":

<figure><img src="https://2470865788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSUfCzMW8qWeXstipFXEh%2Fuploads%2Fgit-blob-a493ea11340fd96321dc431441c47387ee57000e%2Fssl10.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2470865788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSUfCzMW8qWeXstipFXEh%2Fuploads%2Fgit-blob-7cd1b1850b663e9a7d10f2d061906b7193fbe596%2FScreen%20Shot%202022-09-29%20at%204.33.00%20PM.png?alt=media" alt=""><figcaption><p>Configuring a TLS Client Profile</p></figcaption></figure>

## Configuring a Multi-Protocol Gateway Processing Policy

Navigate to Multi-Protocol Gateway and either create or select an existing Multi-Protocol Gateway:

<figure><img src="https://2470865788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSUfCzMW8qWeXstipFXEh%2Fuploads%2Fgit-blob-b3af22783bc193b787d3678ddf2de8b5b8cab324%2Fdp1.png?alt=media" alt=""><figcaption><p>Select Multi-Protocol Gateway</p></figcaption></figure>

<figure><img src="https://2470865788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSUfCzMW8qWeXstipFXEh%2Fuploads%2Fgit-blob-5828667a5e798e3221e7aeda13eac58f91bc8ef8%2Fdp2.png?alt=media" alt=""><figcaption><p>Select an existing or create a new Multi-Protocol Gateway</p></figcaption></figure>

Select an existing or create a new Processing Policy.

<figure><img src="https://2470865788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSUfCzMW8qWeXstipFXEh%2Fuploads%2Fgit-blob-e698cfe2b91b3e1871115039835b2868faca0f15%2Fdp3.png?alt=media" alt=""><figcaption><p>Select an existing or create a new Processing Policy</p></figcaption></figure>

Add a GatewayScript Action as a new Rule and set the Rule Direction to "Both Directions"

<figure><img src="https://2470865788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSUfCzMW8qWeXstipFXEh%2Fuploads%2Fgit-blob-5436c6973f8395ca19558163b70cafa7ca9f83fb%2Fdp4.png?alt=media" alt=""><figcaption><p>Add a GatewayScript Action as a new Rule</p></figcaption></figure>

Edit the following GatewayScript and replace the "sourceId" with the ID of the Revenium Source that will be metered with DataPower. Also replace the "x-api-key" field with the Revenium Metering Beacon API Key. Please contact the Revenium Customer Success team if you require an API key.

{% hint style="info" %}
The sourceId will become an optional field in an upcoming release
{% endhint %}

```javascript
var urlopen = require('urlopen');
var hm = require('header-metadata');
var sm = require('service-metadata');

var reveniumURL = "https://api.hypercurrent.io/meter/v1/api/event"
var apiKey = "hak_1234"
var assetId = "lkpkW3:7d877eb7-19df-4b4c-8500-2958a4b1c734"
var sslClientProfile = "revenium-metering"

var ctx = session.name('revenium') || session.createContext('revenium');

if (ctx.getVariable("requestId")) {
    var payload = {
        "requestId": ctx.getVariable("requestId"),
        "eventType": "RESPONSE",
        "currentMillis": Date.now()
    }

    var options = {
        target: reveniumURL,
        sslClientProfile: sslClientProfile,
        method: 'post',
        headers: {'x-api-key': apiKey},
        contentType: 'application/json',
        timeout: 60,
        data: JSON.stringify(payload)
    };

    urlopen.open(options, function (error, response) {
        response.disconnect()
    });

} else {

    ctx.setVariable("requestId", sm.getVar("var://service/global-transaction-id"));

    var payload = {
        "requestId": ctx.getVariable("requestId"),
        "eventType": "REQUEST",
        "assetId": assetId,
        "productKey": hm.current.get("x-revenium-product-key"),
        "uri": sm.getVar("var://service/URL-in"),
        "method": sm.protocolMethod,
        "currentMillis": Date.now()
    }

    var options = {
        target: reveniumURL,
        sslClientProfile: sslClientProfile,
        method: 'post',
        headers: {'x-api-key': apiKey},
        contentType: 'application/json',
        timeout: 60,
        data: JSON.stringify(payload)
    };

    urlopen.open(options, function (error, response) {
        response.disconnect()
    });
}

```

Finally, upload the script and apply the Policy. Once this is done, this API is successfully set up for Revenium metering.

<figure><img src="https://2470865788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSUfCzMW8qWeXstipFXEh%2Fuploads%2Fgit-blob-f7b0016d7ffab0af532b52424571d97e8d8aa369%2Fdp5.png?alt=media" alt=""><figcaption></figcaption></figure>
