On this page

Pass an object containing the current device ID. getPanelAgentCreditsAccount({ devId }).

getPanelAgentCreditsAccount

Requires:
@tuya-miniapp/cloud-api≥1.7.4

Method signature
getPanelAgentCreditsAccount(params: )

Description

Query the device's current Credits account.

Parameters

ParameterTypeRequiredDescription
YesdevId of the current device

Return Value

Type: Promise<GetPanelAgentCreditsAccountResult>
Current Credits account and enabled status

Referenced Types

typeGetPanelAgentCreditsAccountResultDevice's current Credits account
| {
      /** 当前设备已启用 Credits */
      subscriptionEnabled: true;
      /** 1 为分销,2 为核销 */
      businessMode: 1 | 2;
      /** 当前生效的套餐 */
      plan: PanelAgentCreditsCurrentPlan;
      /** 可用 Credits 十进制字符串,零余额为 "0" */
      remainingCredits: string;
      reset: {
        /** 当前设备可用的重置次数 */
        remaining: number;
      };
    }
  | {
      /** 当前设备未启用 Credits */
      subscriptionEnabled: false;
      /** 0 为显式关闭,null 为未配置 */
      businessMode: 0 | null;
      plan: null;
      remainingCredits: null;
      reset: null;
    }

Valid Values

GetPanelAgentCreditsAccountResult.businessMode
ValueDescriptionSince
1--
2--

Examples

Request example

import { getPanelAgentCreditsAccount } from '@tuya-miniapp/cloud-api';

getPanelAgentCreditsAccount({ devId: 'demo_device' })
  .then(account => console.log(account.subscriptionEnabled, account.remainingCredits))
  .catch(error => console.error('Failed to query Credits account', error));

Response example

{
  "subscriptionEnabled": true,
  "businessMode": 1,
  "plan": {
    "code": "FREE",
    "externalCode": null,
    "capacityCredits": 40,
    "hourlyRecoveryCredits": 4,
    "initialResetCount": 1,
    "isSubscribed": false
  },
  "remainingCredits": "0",
  "reset": { "remaining": 0 }
}

When subscriptionEnabled is false, plan, remainingCredits, and reset are null. A businessMode of 0 indicates that Credits is disabled for the device, and null indicates that it is unconfigured.

Current plan and balance

When enabled, plan is the active plan. See Plan fields for its benefits.

FieldDescription
plan.isSubscribedWhether the active plan is a paid service.
plan.isTrialTrial state of the current credential, when available.
plan.skuCodeSKU code for the current purchase, when available.
plan.periodUnit, plan.periodValuePeriod unit and value for the current purchase, when available.
remainingCreditsA decimal string. An enabled account with zero Credits returns "0".
reset.remainingThe number of resets available to the current device.

Credits and VAS integration example