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

Create

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

Create a new credit grant

Parameters
customer_idString

the Metronome ID of the customer

formatuuid
expires_atTime

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

formatdate-time
grant_amountobject
{ amount, credit_type_id}

the amount of credits granted

Hide ParametersShow Parameters
amountFloat
credit_type_idString

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

formatuuid
nameString

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

priorityFloat
credit_grant_typeString
optional
custom_fieldshash
optional
Hash[Symbol, String]

Custom fields to attach to the credit grant.

effective_atTime
optional

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

formatdate-time
invoice_dateTime
optional

The date to issue an invoice for the paid_amount.

formatdate-time
product_idsarray
optional
Array[String]

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

reasonString
optional
rollover_settingsobject
optional
{ expires_at, priority, rollover_amount}

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_atTime

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.

rollover_amountunion
typeunionvalueFloatRolloverAmountMaxPercentage | typeunionvalueFloatRolloverAmountMaxAmount

Specify how much to rollover to the rollover credit grant

Hide ParametersShow Parameters
typeunionvalueFloatRolloverAmountMaxPercentage
typeunionvalueFloatRolloverAmountMaxAmount
uniqueness_keyString
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
dataidStringID
require "metronome_sdk"

metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token")

credit_grant = metronome.v1.credit_grants.create(
  customer_id: "9b85c1c1-5238-4f2a-a409-61412905e1e1",
  expires_at: "2022-04-01T00:00:00Z",
  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
)

puts(credit_grant)
200 Example
{
  "data": {
    "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
  }
}