Report meter events πŸ“Œ

Meter events are the way to tell Plutto how much your customers are using each feature

In a previous section we created a meter. Meter events represent the usage of this meters.

For example, if you created a meter "Downloads", you should use meter events to report when your customers download files so we can have the count and charge them accordingly.

For each customer, there's a Meter Count that's automatically created. Meter events modify this count.

Meter events have the following parameters:

  • meter_id: the id of the meter you want to modify.
  • customer_id: the id (or identifier) of the customer whose count you want to modify
  • action: you can increment, decrement or set the count
  • amount: the number of events you want to increment, decrement or set
  • timestamp: the date when the event happened. This is optional and it does not have any effect in the order the events are stored or charged. It's for future statistics.

To create a meter event, just make this request:

curl --request POST \
     --url https://example.com/api/v1/meter_events \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --data '
{
     "action": "set",
     "customer_id": "customer_5198c6ad60c3363b089a1421",
     "meter_id": "meter_46cf463812d56103d1dfa382",
     "amount": 1
}
'

Notes

You can report events everytime they happen with incremet and amount: 1 but you can also report events periodically. For example, once a day, week or month. Depends on your use case which is better for you.

🚧

The "set" action will discard the current count value

When you use the "set" action the value will replace the current count value. This could be used for setting initial values or fixing the count if there's an error.


What’s Next

Now jump to our API Reference and take just a few minutes to setup everything!