Building and monetizing asynchronous apis

Hi

We are writing a proxy for our backend api, but it's more of a asynchronous call i.e. when client call our api, we return back a operation id and then we provide another endpoint to get the status using the operation id. My question here is how do I setup monetization for successful asynchronous api calls?

0 7 274
7 REPLIES 7

What's your definition of a successful / monetizable async api call?

It's possible to monetize the initial request but if the async call is not successful or if you only want to monetize the client when making the secondary request this approach wont be suitable. 

You could monetize the secondary request, and assuming you want to avoid monetizing duplicate calls you could cache or store in a memory database the operation id to only monetize the call the first time. This comes with the gap that if a client makes initial async requests but never gets the response those won't be monetized.

Otherwise I think you'll need to custom implement a monetization solution.

I like the option suggested by you. So, monetization of secondary call when it returns 200 code. But send code 200 only when the process is complete. Till then send some other code indicating the request is still under progress 

Keep in mind, I'm not sure how you want to handle duplicate calls to get the response. Maybe you only want to monetize the first time they get the response? There are variables you can set such as transactionSuccess for further control

https://cloud.google.com/apigee/docs/api-platform/monetization/capture-monetization-data

As mentioned, this comes with the downside if they never get the response and only initiate the async request, it wont be monetized. But it comes with the tradeoff of easier to implement.

Is it possible to do a Rest call from backend to Apigee and update monetization data for a transaction?

I think the challenge with this is having context of the original API consumer you want to charge against, the API product etc. You can't retrospectively update monetization data either to my knowledge

If there is any information like product id, I can add that to the header and use it. But retrospective update isn't possible as you say. How else I can design this? Drupal is out of picture for us for the time being 

I am thinking one more solution as creating external database and storing state of each transaction. Is it possible to combine that with monetization report?