Initialize Account Balance

Calling this interface can initialize the current user's global account balance. If the user already has a balance record, it will directly return the existing balance information; if not, it will create a new balance record.

Prerequisites

  1. Register and log in to the Ace Data Cloud platform.
  2. Obtain the Platform Token, for details please refer to the Platform Token Documentation.

Interface Description

  • Request Method: POST
  • Request URL: https://platform.acedata.cloud/api/v1/balances/initialize/
  • Request Headers:
    • accept: application/json
    • authorization: Bearer {token}

Where {token} is the Platform Token.

CURL Request Example

curl -X POST \
  -H "accept: application/json" \
  -H "authorization: Bearer {token}" \
  "https://platform.acedata.cloud/api/v1/balances/initialize/"

Return Result Example

{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "user_id": "user-uuid",
  "credits": "100.00",
  "packages": [
    {
      "id": "pkg-uuid",
      "name": "Basic Package",
      "amount": 100,
      "price": "9.90"
    }
  ],
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:30:00Z"
}

Return Field Description

Field Type Description
id string Unique identifier for the balance record
user_id string User ID
credits string Current global balance (points)
packages array Associated package list
created_at string Creation time
updated_at string Update time

Use Cases

  1. After new user registration: Ensure the user has a global balance record, which can be recharged by purchasing packages later.
  2. Balance check: Before making API calls, first initialize and check if the balance is sufficient.

Code Example

Python:

import requests

token = "your-platform-token"
url = "https://platform.acedata.cloud/api/v1/balances/initialize/"
headers = {
    "accept": "application/json",
    "authorization": f"Bearer {token}",
}

response = requests.post(url, headers=headers)
balance = response.json()
print(f"Current balance: {balance['credits']} points")