Xuất hóa đơn Xuất chi tiết hóa đơn đã lọc thành tệp Excel.
Lọc theo thời gian và tên API Key/mô hình tùy chọn. Thành công trả Excel; lỗi xác thực, kiểm tra hay xử lý có thể trả JSON với HTTP 200. Kiểm tra Content-Type và thân phản hồi.
token <token>
Token xác thực hóa đơn được gửi trong Header token, không có Bearer. Try It nhận token truy cập hệ thống tạo trong cài đặt cá nhân rồi tự lấy thông tin hóa đơn; ví dụ mã có đầy đủ quy trình.
Vị trí truyền: header
Định nghĩa kiểu TypeScript
Sử dụng kiểu request body trong TypeScript.
Sao chépSao chép kiểu TS của phản hồi
cURL
JavaScript
Go
Python
Java
C#
Rustset -euo pipefail
ACCESS_TOKEN='your-user-token'
BILLING_TOKEN=$(curl --fail --silent --show-error "https://api.agtcloud.cn/api/user/self" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" | \
jq -er '
select(.success == true)
| .data.remark | fromjson | .token
| select(type == "string" or type == "number")
| tostring | select(length > 0)
')
response_file=$(mktemp './.bill_export.XXXXXX')
[[ "$response_file" == ./.bill_export.* && -f "$response_file" && ! -L "$response_file" ]] || exit 1
trap 'if [[ "$response_file" == ./.bill_export.* && -f "$response_file" && ! -L "$response_file" ]]; then rm -f -- "$response_file"; fi' EXIT
response_meta=$(curl --silent --show-error "https://api.agtcloud.cn/bill/excel" \
-X POST \
-H "token: ${BILLING_TOKEN}" \
-H 'Content-Type: application/json' \
-d '{
"type": 3,
"startTime": 1791561600,
"endTime": 1792511999
}' \
--output "$response_file" \
--write-out '%{http_code}\n%{content_type}')
http_status=${response_meta%%$'\n'*}
content_type=${response_meta#*$'\n'}
if [[ "$http_status" != 200 || "${content_type%%;*}" != application/vnd.openxmlformats-officedocument.spreadsheetml.sheet || ! -s "$response_file" ]]; then
printf 'Export failed: HTTP %s (%s)\n' "$http_status" "$content_type" >&2
if [[ "${content_type%%;*}" == application/json ]]; then
jq '{code, message}' "$response_file" >&2
fi
exit 1
fi
if [[ -e bill_export.xlsx || -L bill_export.xlsx ]]; then
printf 'bill_export.xlsx already exists; choose another filename.\n' >&2
exit 1
fi
mv -n -- "$response_file" bill_export.xlsx
if [[ -e "$response_file" ]]; then
printf 'bill_export.xlsx already exists; choose another filename.\n' >&2
exit 1
fi
printf 'Saved bill_export.xlsx\n' 200
Tệp Excel (.xlsx) Lưu thành .xlsx, không phân tích như JSON. cURL hỗ trợ --output bill_export.xlsx.