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

Create

Create a credit grant
client.V1.CreditGrants.New(ctx, body) (*DataIDV1CreditGrantNewResponse, error)
post/v1/credits/createGrant

Create a new credit grant

Parameters
bodyCustomerIDfieldExpiresAtfieldGrantAmountfieldNamefieldPaidAmountfieldPriorityfieldCreditGrantTypefieldCustomFieldsfieldEffectiveAtfieldInvoiceDatefieldProductIDsfieldReasonfieldRolloverSettingsfieldUniquenessKeyfieldV1CreditGrantNewParams
Hide ParametersShow Parameters
CustomerIDfield
param.Field[string]

the Metronome ID of the customer

formatuuid
ExpiresAtfield
param.Field[Time]

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

formatdate-time
GrantAmountfield

the amount of credits granted

Hide ParametersShow Parameters
Amountfloat64
CreditTypeIDstring

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

formatuuid
Namefield
param.Field[string]

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

Priorityfield
param.Field[float64]
CreditGrantTypefield
optional
param.Field[string]
CustomFieldsfield
optional
param.Field[map[string, string]]

Custom fields to attach to the credit grant.

EffectiveAtfield
optional
param.Field[Time]

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

formatdate-time
InvoiceDatefield
optional
param.Field[Time]

The date to issue an invoice for the paid_amount.

formatdate-time
ProductIDsfield
optional
param.Field[[]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

Reasonfield
optional
param.Field[string]
RolloverSettingsfield
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
ExpiresAtTime

The date to expire the rollover credits.

formatdate-time
Priorityfloat64

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

RolloverAmountRolloverAmountMaxPercentagestruct{…}RolloverAmountMaxAmountstruct{…}V1CreditGrantNewParamsRolloverSettingsRolloverAmount

Specify how much to rollover to the rollover credit grant

Hide ParametersShow Parameters
RolloverAmountMaxPercentagestruct
Hide ParametersShow Parameters
TypeRolloverAmountMaxPercentageTypeMaxPercentageRolloverAmountMaxPercentageTypeRolloverAmountMaxPercentageType

Rollover up to a percentage of the original credit grant amount.

Hide ParametersShow Parameters
RolloverAmountMaxPercentageTypeMaxPercentageconst
RolloverAmountMaxPercentageTypeMaxPercentageRolloverAmountMaxPercentageTypeRolloverAmountMaxPercentageType
"MAX_PERCENTAGE"
Valuefloat64

The maximum percentage (0-1) of the original credit grant to rollover.

minimum0
maximum1
RolloverAmountMaxAmountstruct
Hide ParametersShow Parameters
TypeRolloverAmountMaxAmountTypeMaxAmountRolloverAmountMaxAmountTypeRolloverAmountMaxAmountType

Rollover up to a fixed amount of the original credit grant amount.

Hide ParametersShow Parameters
RolloverAmountMaxAmountTypeMaxAmountconst
RolloverAmountMaxAmountTypeMaxAmountRolloverAmountMaxAmountTypeRolloverAmountMaxAmountType
"MAX_AMOUNT"
Valuefloat64

The maximum amount to rollover.

UniquenessKeyfield
optional
param.Field[string]

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
V1CreditGrantNewResponsestruct
Hide ParametersShow Parameters
DataIDstringID
package main

import (
  "context"
  "fmt"
  "time"

  "github.com/Metronome-Industries/metronome-go"
  "github.com/Metronome-Industries/metronome-go/option"
)

func main() {
  client := metronome.NewClient(
    option.WithBearerToken("My Bearer Token"),
  )
  creditGrant, err := client.V1.CreditGrants.New(context.TODO(), metronome.V1CreditGrantNewParams{
    CustomerID: metronome.F("9b85c1c1-5238-4f2a-a409-61412905e1e1"),
    ExpiresAt: metronome.F(time.Now()),
    GrantAmount: metronome.F(metronome.V1CreditGrantNewParamsGrantAmount{
      Amount: metronome.F(1000.000000),
      CreditTypeID: metronome.F("5ae401dc-a648-4b49-9ac3-391bb5bc4d7b"),
    }),
    Name: metronome.F("Acme Corp Promotional Credit Grant"),
    PaidAmount: metronome.F(metronome.V1CreditGrantNewParamsPaidAmount{
      Amount: metronome.F(5000.000000),
      CreditTypeID: metronome.F("2714e483-4ff1-48e4-9e25-ac732e8f24f2"),
    }),
    Priority: metronome.F(0.500000),
    CreditGrantType: metronome.F("trial"),
    EffectiveAt: metronome.F(time.Now()),
    Reason: metronome.F("Incentivize new customer"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", creditGrant.Data)
}
200 Example
{
  "data": {
    "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
  }
}