Aller au contenu principal

Get customer totals

Thread solved
Beginner
Contributions: 1
Commentaires: 4

Hi all,

Can somebody help me to get the customer totals (total cloud storage size) via the API?

I managed to create a custom search to a Client ID.

 

0 Users found this helpful
Forum Member
Contributions: 1
Commentaires: 44

#1

It mostly depends for what you need to have it.

For informational purposes you can use GET /tenant/{tenant_id}/usages - it updates every 5-6 hours, thus, not expected to be called more then 4 times per day.

For billing purposes you should use the /reports endpoint. So, for your case it might be like this:
1. Create report - POST /reports with schedule once and action save.
2. Take the stored report info GET /reports/{{report_id}}/stored
3. Download the report GET /reports/{{report_id}}/stored/{{stored_report_id}}
4. Delete the report if you don't need it DELETE GET /reports/{{report_id}}
5. Parse the report and find what you need (usage.xxxx.total fields)

The reports always provide the data for 23:59:59 (last day for report), thus if you ask for report for now, you will receive the date for the day-1, midnight.

Beginner
Contributions: 1
Commentaires: 4

#2

Ok, got it almost.

Is it possible þo only get the csv data?

The first 9 lines contains data i don't need.

I am automating things...

 

The first 9 lines contain:

sep=,
Tenant name,<DEDACTED>
Report type,Summary for period
Date of report generation,2020-05-12
Reporting period,2020-04-01 - 2020-04-30
Level of detail,All customers and partners (including user details)

Forum Member
Contributions: 1
Commentaires: 44

#3

When you use API, the way I proposed above, you should receive only CSV data. Your example looks like an e-mailed report which expects to be a little bit more human readable.

Beginner
Contributions: 1
Commentaires: 4

#4

I used this in my python script:

report_data = {
     "parameters": {
         "kind": "usage_summary",
         "tenant_id": tenant_id,
         "level": "accounts",
         "period": {
             "start": "2020-04-01",
             "end": "2020-04-30"
         },
         "formats": [
             "csv"
         ]
     },
     "schedule": {
         "type": "once"
     },
     "generation_date": "2020-05-12",
     "result_action": "save"
 }
Forum Member
Contributions: 1
Commentaires: 44

#5

Oh, I see. Please use csv_v2_0 for the format. Sorry, I totally forgot about csv format which is by default used for send action reports.

Beginner
Contributions: 1
Commentaires: 4

#6

Ok that works but the next problem is dat Partner accounts are not listed here, no totals.

This is my python script i use:

import requests
import json
import pprint
import time
account_creds = ''<DEDACTED>', '<DEDACTED>'
base_url = 'https://eu-baas.acronis.com/api/2'
response = requests.get(f'{base_url}/users/me', auth=account_creds)
user_account = response.json()
#pprint.pprint(user_account)

tenant_id = user_account['tenant_id']

client_info = {
     'type': 'agent',
     'tenant_id': tenant_id,
     'token_endpoint_auth_method': 'client_secret_basic',
     'data': {'name': 'vCron'},
 }

client_info = json.dumps(client_info, indent=4)
#print(client_info)

response = requests.post(
     f'{base_url}/clients',
     auth=account_creds,
     headers={'Content-Type': 'application/json'},
     data=client_info,
 )
#response.status_code

client = response.json()
#pprint.pprint(client)
client_creds = client['client_id'], client['client_secret']

response = requests.post(
     f'{base_url}/idp/token',
     auth=client_creds,
     headers={'Content-Type': 'application/x-www-form-urlencoded'},
     data={'grant_type': 'client_credentials'},
 )
#response.status_code

token_info = response.json()
#pprint.pprint(token_info)
auth = {'Authorization': 'Bearer ' + token_info['access_token']}

# Create Report
report_data = {
     "parameters": {
         "kind": "usage_summary",
         "tenant_id": tenant_id,
         "level": "accounts",
         "period": {
             "start": "2020-04-01",
             "end": "2020-04-28"
         },
         "formats": [
             "csv_v2_0"
         ]
     },
     "schedule": {
         "type": "once"
     },
     "generation_date": "2020-05-13",
     "result_action": "save"
 }
 
report_data = json.dumps(report_data, indent=4)

response = requests.post(
     f'{base_url}/reports',
     headers={'Content-Type': 'application/json', **auth},
     data=report_data,
)
#response.status_code
#pprint.pprint(response.json())
 
report_id = response.json()['id']
version = response.json()['version']
 
# Fetch Report
response = requests.get(f'{base_url}/reports/{report_id}', headers=auth)
#pprint.pprint(response.json())

# Wait for 30 seconds
time.sleep(30)

# Fetching stored reports
response = requests.get(f'{base_url}/reports/{report_id}/stored', headers=auth)
#pprint.pprint(response.json())
stored_reports = response.json()['items']
stored_report_id = [stored_report['id'] for stored_report in stored_reports if stored_report['report_format'] == 'csv_v2_0' and stored_report['status'] == 'saved'][-1]
response = requests.get(f'{base_url}/reports/{report_id}/stored/{stored_report_id}', headers=auth)
#pprint.pprint(response.json())

# Download Report
open(''<DEDACTED>:/'<DEDACTED>/acronis_report.csv', 'wb').write(response.content)

# Delete report
response = requests.delete(f'{base_url}/reports/{report_id}/stored/{stored_report_id}', headers=auth)

 

Basically what i want is get all the Custom_ID and loop trough them and get all the totals.

 

Forum Member
Contributions: 1
Commentaires: 44

#7

You've asked in your first message, how to find customers totals. The report you've created and downloaded contains all totals for the partners and customers hierarchy for specified tenant_id, including users details. There are 3 other types of reports:

direct_partners

The report will include direct customers and partners.

all_partners

The report will include all partners.

all_customers

The report will include all customers and partners

The report contains totals for all specific usages mentioned here https://developer.acronis.com/doc/account-management/v2/guide/usage-reporting/index

Bellow, the header of csv_v2_0 report.

application.id,application.name,date,infra.backend_type,infra.id,infra.name,infra.owner_id,is_range,measurement_unit,name,pricing.currency,pricing.mode,pricing.price,pricing.total_cost,quota.value,tenant.customer_id,tenant.id,tenant.kind,tenant.name,usage.absolute.production,usage.absolute.total,usage.absolute.trial,usage.delta.production,usage.delta.total,usage.delta.trial,usage.effective.production,usage.effective.total,usage.effective.trial,edition

The field name -- contains name of a usage, for storage there are, depending on an edition and an application, storage, adv_storage, dr_storage, dre_storage etc. and a usage.<type>.total fields contain total usage for a specific storage type for a specific tenant.

If you just want to have kind of "total_storage" field like in /tenant/{tenant_id}/usages response, you may try to use json_v1 and json_v2_0 reports formats.  

Beginner
Contributions: 1
Commentaires: 4

#8

I cannot get the values as seen in the screenshot.

I need the values that are in the totals.

on all customers and partners i entered a Custom ID

So i need to filter on the Custom ID and than get the total values.

I do not care what the Partners underneeth have as we are billing our partners and not his customers.

 

Fichier attaché Taille
538115-184622.png 65.48 Ko
Forum Member
Contributions: 1
Commentaires: 44

#9

All these total values are in the report. I sure, as I did PoC last week with this report and Excel datasheet. Depending on an edition it will be following values in name  field:
Cyber Backup Editions
              Standard                 storage
              Advanced                adv_storage 
              Disaster Recovery  dre_storage

Cyber Protect Editions
             Standard                  p_storage
             
Advanced                 p_adv_storage
             
Disaster Recovery   p_dre_storage.

All the values are in bytes.

Custom ID from the portal are the tenant.customer_id field at the report

The total value for the production storage usage should be at the usage.absolute.production field.

Types:

absolute - absolute usage value for the end of report period as reported to Platform
delta - delta of given usage between report period start date and report period end date
effective - usage value for the end of report period for non-range usages (equal to absolute value) and delta value for range usages

For the storage usage effective and absolute the same.

If you have "old" Disaster Recovery storage, you might find as well dr_storage in your report.