2.10. 将 CSV 文件发送到成本管理
要将 CSV 文件发送到成本管理,请请求服务帐户令牌进行 API 身份验证。
-
在以下 curl 命令中,将
my_client_id
和my_client_secret
替换为您的实际值:
curl --location 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token' -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'client_id=my_client_id' --data-urlencode 'client_secret=my_client_secret' --data-urlencode 'grant_type=client_credentials'
curl --location 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token' -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'client_id=my_client_id' --data-urlencode 'client_secret=my_client_secret' --data-urlencode 'grant_type=client_credentials'
- 响应示例:
{"access_token":"ENCRYPTED_TOKEN","expires_in":900,"refresh_expires_in":0,"token_type":"Bearer","not-before-policy":0,"scope":""}
{"access_token":"ENCRYPTED_TOKEN","expires_in":900,"refresh_expires_in":0,"token_type":"Bearer","not-before-policy":0,"scope":""}
-
发送 API 请求以成本管理,并指出哪些 CSV 报告已准备好被处理。以下是请求示例:在您的请求中,使用您的令牌更新
ENCRYPTED_TOKEN
,使用您的 C.R.C集成 ID
,使用您的 C.R.C 集成 ID、file_LIST
以及您的 CSV 文件列表更新 ENCRYPTED_TOKEN,以及您的文件日期的MONTH
。
curl -X POST --location https://console.redhat.com/api/cost-management/v1/ingress/reports/' -H 'Authorization: Bearer ENCRYPTED_TOKEN' -H 'Content-Type: application/json' -d '{"source": "my-integration-id", "bill_year": "2025", "bill_month": "03", "reports_list": ["my-csv-file.csv"]}'
curl -X POST --location https://console.redhat.com/api/cost-management/v1/ingress/reports/' -H 'Authorization: Bearer ENCRYPTED_TOKEN' -H 'Content-Type: application/json' -d '{"source": "my-integration-id", "bill_year": "2025", "bill_month": "03", "reports_list": ["my-csv-file.csv"]}'
- 响应示例:
{'meta': {'count': 8, 'limit': 10, 'offset': 0}, 'links': {'first': '/api/cost-management/v1/ingress/reports/?limit=10&offset=0', 'next': None, 'previous': None, 'last': '/api/cost-management/v1/ingress/reports/?limit=10&offset=0'}, 'data': {'source': 'source_uuid', 'source_id': source_id, 'reports_list': ['my-csv-file.csv'], 'bill_year': '2025', 'bill_month': '03', 'schema_name': 'my-schema', 'ingress_report_uuid': 'report-uuid', 'status': 'pending'}}
{'meta': {'count': 8, 'limit': 10, 'offset': 0}, 'links': {'first': '/api/cost-management/v1/ingress/reports/?limit=10&offset=0', 'next': None, 'previous': None, 'last': '/api/cost-management/v1/ingress/reports/?limit=10&offset=0'}, 'data': {'source': 'source_uuid', 'source_id': source_id, 'reports_list': ['my-csv-file.csv'], 'bill_year': '2025', 'bill_month': '03', 'schema_name': 'my-schema', 'ingress_report_uuid': 'report-uuid', 'status': 'pending'}}
发送 CSV 文件后,您已成功与 GCP 集成。如果要自动化这个过程,请参阅 第 3.1 节 “使用示例代码片段自动创建和发送报告”。