Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Best Practice for Monetizing API Based on Service in Request Body (Single Service)

Amr
Bronze 5
Bronze 5

 

Dears, I hope you are doing well,

We are implementing Apigee Monetization (OPDK) and have a requirement where an API receives requests for different services, each with its own price. The requested service is passed in the body of the request, and each request contains only one service.

Here is the service-level pricing:

  • $8 per request for: OpenAccount, CloseAccount, SuspendAccount
  • $5 per request for: Login, Logout
  • $3 per request for: PersonalLoan, VehicleLoan

Example Request Format:

Show More
{
"id": "1",
"service": "OpenAccount"
}

We would like your recommendation on the best practice for implementing this pricing model using Apigee Monetization (OPDK), specifically how to:

  • Dynamically charge based on the service field in the request body
  • Apply the correct price based on the service name
  • Accurately track monetization metrics and usage per service

Note: This is only for POSTPAID developers.

We are open to any recommended architecture or implementation pattern, including usage of custom attributes, API product configurations, or rate plans.

Please advise on how to approach this requirement effectively. Let us know if additional context is needed.

Thank you,

Solved Solved
1 7 233
1 ACCEPTED SOLUTION

Hi @Amr 

I think you an accomplish what you want using a custom attribute in the Transaction Recording Policy of the Product Bundle. For example, I set a flow variable "delivered_count" to represent the count I want to use to multiply the rate from the rate plan in the response.

kurtkanaskie_0-1750689815823.png

My Rate Plan 

kurtkanaskie_1-1750689882719.png

Then in an Assign Message for my response I set the value of the "delivered_count" variable.

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-create-status-response">
    <DisplayName>AM-create-status-response</DisplayName>
    <AssignVariable>
        <Name>delivered_count</Name>
        <Value>5</Value>
    </AssignVariable>
    <Set>
        <Headers>
            <Header name="Content-Type">application/json</Header>
            <Header name="X-monetization-status">OK</Header>
        </Headers>
        <Payload contentType="application/json">
{
    "developerEmail":"{developer.email}",
    "application": "{verifyapikey.VA-header.developer.app.name}",
    "product": "{verifyapikey.VA-header.apiproduct.name}",
    "apiproxy": "{apiproxy.name}",
    "apiproxyRevision": "{apiproxy.revision}",
    "basepath": "{proxy.basepath}",
    "suffix": "{proxy.pathsuffix}",
    "message":"STATUS",
    "delivered_count":{delivered_count}
}
</Payload>
        <StatusCode>200</StatusCode>
        <ReasonPhrase>OK</ReasonPhrase>
    </Set>
</AssignMessage>

The result is that the developer will be charged 5 X $0.05 = $0.25 for this call.

In your use case, you could create a rate plan with a rate of $1.00 for a limited band and $1.00 for unlimited calls.

kurtkanaskie_2-1750690672651.png

Then set a flow variable (e.g. delivered_count) for each flow cost (e.g. 3, 5 and 8).

Hope that helps.

View solution in original post

7 REPLIES 7