GoliathDevelopersGet an API key
Reference/Billinggenerated from the gateway manifest

setCreditAutoRecharge

Save one credit type's auto-recharge, as Billing > Credits does.

POST/api/v1/callADMINidempotent · 24 hruns as the key's owner
View as Markdown

Save one credit type's auto-recharge, as Billing > Credits does: on, it buys selectedPackCode (rechargeAmountCents its price) on the card on file when the balance falls below thresholdUnits, at most maxBudgetCents a billing period. Switching it on saves every field: read getCreditAutoRecharge, send the rest unchanged, and take rechargeAmountCents from getCreditPrices for the selected pack (refused when it moved); enabled: false only switches it off. Org admins only. When asked first, the card of a save that turns it on names the pack's exact price (rechargeAmountCents, getCreditPrices', refused when it moved), the period budget, that a pack is non-refundable, the threshold and the card. Saving may buy a pack at once if the balance is already low.

curl https://server.goliathdata.com/api/v1/call \
  -H "Authorization: Bearer $GOLIATH_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "operationId": "setCreditAutoRecharge",
    "variables": {
      "creditType": "EXPORT_PROPERTIES",
      "enabled": true,
      "thresholdUnits": 10,
      "rechargeAmountCents": 10,
      "maxBudgetCents": 10
    }
  }'
import { GoliathClient } from '@goliath-data/sdk'

const goliath = new GoliathClient({
  apiKey: process.env.GOLIATH_API_KEY!,
  baseUrl: 'https://server.goliathdata.com',
})

// Enum values as strings: the SDK's enum types aren't exported yet, so assert to the method's variables type.
const variables = {
  creditType: 'EXPORT_PROPERTIES',
  enabled: true,
  thresholdUnits: 10,
  rechargeAmountCents: 10,
  maxBudgetCents: 10
} as Parameters<typeof goliath.billing.setCreditAutoRecharge>[0]

const result = await goliath.billing.setCreditAutoRecharge(variables, { idempotencyKey: crypto.randomUUID() })
const res = await fetch('https://server.goliathdata.com/api/v1/call', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.GOLIATH_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': crypto.randomUUID(),
  },
  body: JSON.stringify({
    operationId: 'setCreditAutoRecharge',
    variables: {
      creditType: 'EXPORT_PROPERTIES',
      enabled: true,
      thresholdUnits: 10,
      rechargeAmountCents: 10,
      maxBudgetCents: 10
    }
  }),
})
const { data, errors } = await res.json()

Variables

The example sends only what the schema requires. Some operations also need one of several optional variables (one filter or another, say); the description above says which.

creditTypeCreditType!required

AI_CREDITS: AI agent usage (AI Agent Credits). Purchase-only: 1 credit = 1 cent. SMS_CREDITS: Texting credits. One credit equals one outbound carrier text segment. CALLING_MINUTES: Calling minutes: talk minutes on managed lines, both directions, rounded up per call. Plan allowance first, then purchased packs; the balance can be negative.

EXPORT_PROPERTIESSKIPTRACEEMAIL_VERIFICATIONAI_CREDITSSMS_CREDITSCALLING_MINUTES
enabledBoolean!required
thresholdUnitsInt!required
selectedPackCodeString
rechargeAmountCentsInt!required
maxBudgetCentsInt!required

Response

What comes back under data: a list shows as one entry, and a value as its type.

response shape
{
  "data": {
    "orgCreditAutoRechargeMutation": {
      "update": {
        "creditType": "EXPORT_PROPERTIES",
        "enabled": true,
        "thresholdUnits": 0,
        "selectedPackCode": "…",
        "rechargeAmountCents": 0,
        "maxBudgetCents": 0,
        "spentThisPeriodCents": 0
      }
    }
  }
}

Errors

Idempotency

Send an Idempotency-Key of 1 to 255 characters. A finished request retried with the same key replays its stored response, marked Idempotency-Replayed: true; one still in flight returns 409 idempotency_conflict. Keys expire after 24 hours. Write without fear →