Ingest Custom Actions - Collector API

You can directly send custom events to Moesif’s Track Actions API. Actions have an action name (like “Sent Message” or “Finished Job”) which represents the raw event. You can also include arbitrary metadata. Any metadata fields you set can be used to create billable metrics (such as for usage-based billing), quotas, reports, alerts, and more. For more info, see docs on actions.

Limitations

Enforcing quotas and governance rules will not work without a server integration. You can always install a server integration later if this capability is required.

Send an Action

The action can be sent to the Collector API like below. The metadata field should contain any attributes you would like associated with this action and can be any JSON object. Moesif is designed for high-dimensions, high-cardinality event data, so it’s ok to include a lot of relevant fields even if you don’t require them today.

curl -X POST \
  https://api.moesif.net/v1/actions \
  -H 'Content-Type: application/json' \
  -H 'X-Moesif-Application-Id: Your_Moesif_Application_Id' \
  -d '{
    "action_name": "Processed Payment Transaction",
    "request": {
      "time": "2024-03-01T04:45:42.914"
    },
    "company_id": "12345",
    "transaction_id": "a3765025-46ec-45dd-bc83-b136c8d1d257",
    "metadata": {
      "amount": 24.6,
      "currency": "USD",
      "time_seconds": 66.3
    }
  }'

You’ll want to set a few fields like below:

  • action_name is a string and should include name of the event such as “Processed Payment Transaction”.
  • company_id is the customer identifier (see companies).
  • transaction_id should be a random UUID for this event which Moesif uses for deduplication (docs on Moesif idempotency).
  • request.time represents the transaction time as an ISO formatted string.
  • metadata is an object which includes any custom properties for this event. By setting metadata, you can bill on arbitrary metrics, create metrics on them, etc. For example, if the action name is “Processed Payment Transaction”, you can include an amount and the currency to bill on the total amount.

For full schema and available fields, see Actions API Reference.

In the above example, the action is created whenever a payment is processed. There are also two metrics we are tracking as part of the action (the amount of the payment and how long the job took). You can create billable metrics and usage reports from these attributes.

Send a Batch of Actions

You can also send a batch of actions which can be more efficient in high throughput streams (such as from your Logstash or AWS Firehose). The batch API follows the same schema, but as a JSON array.

curl -X POST \
  https://api.moesif.net/v1/actions/batch \
  -H 'Content-Type: application/json' \
  -H 'X-Moesif-Application-Id: Your_Moesif_Application_Id' \
  -d '[{
    "action_name": "Processed Payment Transaction",
    "request": {
      "time": "2024-03-01T04:45:42.914"
    },
    "company_id": "12345",
    "transaction_id": "a3765025-46ec-45dd-bc83-b136c8d1d257",
    "metadata": {
      "amount": 24.6,
      "currency": "USD",
      "time_seconds": 66.3
    }
  },
  {
    "action_name": "Processed Payment Transaction",
    "request": {
      "time": "2024-03-01T04:46:42.914"
    },
    "company_id": "67890",
    "transaction_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
    "metadata": {
      "amount": 674.12,
      "currency": "USD",
      "time_seconds": 25.9
    }
  }]'

Updated: