Skip to content
  • Auto
  • Light
  • Dark
Talk to an expert

Create

Create a credit grant
v1.credit_grants.create(CreditGrantCreateParams**kwargs) -> dataIDCreditGrantCreateResponse
post/v1/credits/createGrant

Create a new credit grant

Parameters
customer_idstr

the Metronome ID of the customer

formatuuid
expires_atunion
Union[str, datetime]

The credit grant will only apply to usage or charges dated before this timestamp

formatdate-time
grant_amountamountfloatcredit_type_idstrGrantAmount

the amount of credits granted

Hide ParametersShow Parameters
amountfloat
credit_type_idstr

the ID of the pricing unit to be used. Defaults to USD (cents) if not passed.

formatuuid
namestr

the name of the credit grant as it will appear on invoices

priorityfloat
credit_grant_typestr
optional
custom_fieldsDict[str, str]
optional
Dict[str, str]

Custom fields to attach to the credit grant.

effective_atunion
optional
Union[str, datetime]

The credit grant will only apply to usage or charges dated on or after this timestamp

formatdate-time
invoice_dateunion
optional
Union[str, datetime]

The date to issue an invoice for the paid_amount.

formatdate-time
product_idslist
optional
List[str]

The product(s) which these credits will be applied to. (If unspecified, the credits will be applied to charges for all products.). The array ordering specified here will be used to determine the order in which credits will be applied to invoice line items

reasonstr
optional
rollover_settingsexpires_atunionpriorityfloatrollover_amountRolloverSettingsRolloverAmountRolloverSettings
optional

Configure a rollover for this credit grant so if it expires it rolls over a configured amount to a new credit grant. This feature is currently opt-in only. Contact Metronome to be added to the beta.

Hide ParametersShow Parameters
expires_atunion
Union[str, datetime]

The date to expire the rollover credits.

formatdate-time
priorityfloat

The priority to give the rollover credit grant that gets created when a rollover happens.

Specify how much to rollover to the rollover credit grant

Hide ParametersShow Parameters
typeliteralvaluefloatRolloverAmountMaxAmountParam
uniqueness_keystr
optional

Prevents the creation of duplicates. If a request to create a record is made with a previously used uniqueness key, a new record will not be created and the request will fail with a 409 error.

minLength1
maxLength128
Returns
CreditGrantCreateResponseclass
Hide ParametersShow Parameters
dataidstrID
from datetime import datetime
from metronome import Metronome

client = Metronome(
    bearer_token="My Bearer Token",
)
credit_grant = client.v1.credit_grants.create(
    customer_id="9b85c1c1-5238-4f2a-a409-61412905e1e1",
    expires_at=datetime.fromisoformat("2022-04-01T00:00:00"),
    grant_amount={
        "amount": 1000,
        "credit_type_id": "5ae401dc-a648-4b49-9ac3-391bb5bc4d7b",
    },
    name="Acme Corp Promotional Credit Grant",
    paid_amount={
        "amount": 5000,
        "credit_type_id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
    },
    priority=0.5,
    credit_grant_type="trial",
    effective_at=datetime.fromisoformat("2022-02-01T00:00:00"),
    reason="Incentivize new customer",
)
print(credit_grant.data)
200 Example
{
  "data": {
    "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
  }
}