Экспортировать счёт Экспорт отфильтрованных записей счетов в Excel.
Фильтр по периоду и необязательным названиям API Key/модели. Успех возвращает Excel; ошибки авторизации, параметров или обработки могут вернуть JSON с HTTP 200. Проверяйте Content-Type и тело.
token <token>
Токен авторизации счетов передаётся в Header token без Bearer. В Try It вводится системный токен доступа из личных настроек, реквизиты счетов получаются автоматически. Примеры кода включают полный процесс.
Расположение: header
Определения типов TypeScript
Используйте тип request body в TypeScript.
Копировать
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
Файл Excel (.xlsx) Сохраняйте как .xlsx, а не разбирайте как JSON. В cURL: --output bill_export.xlsx.