Metering API (1.1.2)
Download OpenAPI specification:Download
The metering API enables you to track usage of specific resources
by creating and managing transactions
. Transactions are assigned
to keys, which can represent users, etc.
Initialize Key
Keys must be initialized before you can begin tracking their usage.
You should specify accessible resources in items
, along with any
quantity limits or date cutoffs.
The key can only be reset or modified by the user that created it.
Authorizations:
Request Body schema: application/json
audiences required | Array of strings (Id) [ 1 .. 10 ] characters [ items [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ ] |
keyId | string (Id) [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ |
required | Array of objects (Resource) [ 1 .. 10 ] characters [ items ] |
Responses
Request samples
- Payload
{- "audiences": [
- "string"
], - "keyId": "string",
- "resources": [
- {
- "accessUntilDate": "2019-08-24T14:15:22Z",
- "limit": 0,
- "readOnly": false,
- "resetBehavior": "WIPE",
- "resourceId": "string",
- "transactionLimits": {
- "maximumQuantity": 0,
- "minimumQuantity": 0
}
}
]
}
Response samples
- 201
{- "keyId": "string"
}
Describe Key
Get resource usage data for a specific key.
Authorizations:
path Parameters
keyId required | string (Id) [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ |
Responses
Response samples
- 200
{- "keyId": "string",
- "resources": [
- {
- "accessUntilDate": "2019-08-24T14:15:22Z",
- "confirmed": 0,
- "limit": 0,
- "pending": 0,
- "readOnly": false,
- "resetBehavior": "WIPE",
- "resourceId": "string",
- "transactionLimits": {
- "maximumQuantity": 0,
- "minimumQuantity": 0
}
}
]
}
Update Key
Update a key's audience and resource lists. At least one of audiences
or resources
must be provided.
Authorizations:
path Parameters
keyId required | string (Id) [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ |
Request Body schema: application/json
audiences | Array of strings If provided, overwrites the list of audiences allowed to create transactions on this key. |
Array of objects (Resource) [ items ] Updates |
Responses
Request samples
- Payload
{- "audiences": [
- "string"
], - "resources": [
- {
- "accessUntilDate": "2019-08-24T14:15:22Z",
- "limit": 0,
- "readOnly": false,
- "resetBehavior": "WIPE",
- "resourceId": "string",
- "transactionLimits": {
- "maximumQuantity": 0,
- "minimumQuantity": 0
}
}
]
}
Response samples
- 200
{- "audiences": [
- "string"
], - "keyId": "string",
- "resources": [
- {
- "accessUntilDate": "2019-08-24T14:15:22Z",
- "limit": 0,
- "readOnly": false,
- "resetBehavior": "WIPE",
- "resourceId": "string",
- "transactionLimits": {
- "maximumQuantity": 0,
- "minimumQuantity": 0
}
}
]
}
Reset Key
Reset the usage for all resources atomically. Returns the key's usage prior to being
reset - equivalent to Describe Key
before a reset. The resetPending
attribute gives the user the option to either fail if there's a pending
txn, carry it over to the new key, or reset it to zero. Defaults to
'FAIL'. Resources that have the reset behavior set to TRANSFER will
have their usage roll over.
Authorizations:
path Parameters
keyId required | string (Id) [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ |
Request Body schema: application/json
resetPending | string (ResetPendingEnum) Default: "FAIL" Enum: "FAIL" "WIPE" "TRANSFER" |
Array of objects (Resource) [ items ] |
Responses
Request samples
- Payload
{- "resetPending": "FAIL",
- "resources": [
- {
- "accessUntilDate": "2019-08-24T14:15:22Z",
- "limit": 0,
- "readOnly": false,
- "resetBehavior": "WIPE",
- "resourceId": "string",
- "transactionLimits": {
- "maximumQuantity": 0,
- "minimumQuantity": 0
}
}
]
}
Response samples
- 200
{- "keyId": "string",
- "resources": [
- {
- "accessUntilDate": "2019-08-24T14:15:22Z",
- "confirmed": 0,
- "limit": 0,
- "pending": 0,
- "readOnly": false,
- "resetBehavior": "WIPE",
- "resourceId": "string",
- "transactionLimits": {
- "maximumQuantity": 0,
- "minimumQuantity": 0
}
}
]
}
List Transactions
Get list of transactions for a specific key.
Authorizations:
path Parameters
keyId required | string (Id) [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ |
query Parameters
nextToken | string (NextToken) <= 4096 characters ^[a-zA-Z0-9_-]+$ |
status required | string[PENDING|CONFIRMED|CANCELED|EXPIRED]([,PENDIN... Example: status=CANCELED,EXPIRED Results only contain transactions with the specified status type(s). |
Responses
Response samples
- 200
{- "items": [
- {
- "expirationDate": "2019-08-24T14:15:22Z",
- "keyId": "string",
- "quantity": 0,
- "resourceId": "string",
- "status": "PENDING",
- "transactionId": "string"
}
], - "nextToken": "string"
}
Create Transaction
Create a new transaction. Quantity should be an upper bound if unknown, as
adjustments (via PUT /transactions/transactionId
) can only decrease the quantity.
Returns the transactionId
which should be kept track of by your application
in order to describe, confirm, update, or cancel the transaction.
Authorizations:
Request Body schema: application/json
commit | boolean Default: false Immediately commit the transaction |
expiration | number [ 0 .. 86400 ] Default: 3600 Expiration of the transaction in seconds. |
keyId required | string (Id) [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ |
quantity required | number An upper bound on the quantity consumed by the key.
This can be reduced via |
resourceId required | string (Id) [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ |
Responses
Request samples
- Payload
{- "commit": false,
- "expiration": 120,
- "keyId": "string",
- "quantity": 0,
- "resourceId": "string"
}
Response samples
- 201
{- "transactionId": "string"
}
Describe Transaction
Get specific transaction details.
Authorizations:
path Parameters
transactionId required | string (Id) [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ |
Responses
Response samples
- 200
{- "expirationDate": "2019-08-24T14:15:22Z",
- "keyId": "string",
- "quantity": 0,
- "resourceId": "string",
- "status": "PENDING",
- "transactionId": "string"
}
Update Transaction
Update transaction quantity to a reduced value. An increase isn't allowed as it could conflict with limits (initial transaction quantities should be an upper bound). Instead, a new transaction should be initiated.
Transactions can only be updated by the user and application that created the transaction.
Authorizations:
path Parameters
transactionId required | string (Id) [ 1 .. 64 ] characters [a-zA-Z0-9_-]+ |
Request Body schema: application/json
quantity required | number The (reduced) quantity consumed. |
Responses
Request samples
- Payload
{- "quantity": 0
}