Billing report error 415
Hello everyone! I'm having trouble generating the billing report. The authentication is correct, below is the code I'm using and the error code:
report = {
"parameters": {
"kind": "usage_summary",
"level": "direct_partners",
"tenant_id": "MyID",
"formats": [
"csv_v2_0"
],
"period": {
"start": "2022-01-01",
"end": "2022-02-01"
},
"show_skus": "true",
"hide_zero_usage": "true"
},
"schedule": {
"type": "once"
},
"result_action": "save"
}
billing_report = requests.post(f'{base_url}/reports', data=json.dumps(report), headers=auth)
billing_report.text
Error:
'{"error": {"code": 415, "domain": "PlatformReportingService", "message": "Unsupported Media Type", "details": {}}}'
Cheers to all!

- Log in to post comments

Hello Mad Logan.
Please check this user-guide and make sure you introduce the correct parameters: https://developer.acronis.com/doc/account-management/v2/guide/usage-rep…
Thanks in advance!
- Log in to post comments

Hi Jose Pedro!
I have another question
how can i list all created reports?
- Log in to post comments

Mad Logan wrote:Hi Jose Pedro!
I have another question
how can i list all created reports?
Hello !
Where do you want to list them? Once the reports are generated they should simply be sent. There's no such option as list them.
Thanks in advance!
- Log in to post comments

Hello Jose Pedro!
I would like to see the reports created, stored reports and remove the ones I won't use, since I created some for testing. It would just be to clean up the clutter.
The problem is that I don't have all the IDs of the reports already created, so I wanted to list the reports, but the question would be, how to list the IDs of the reports already created
- Log in to post comments

Mad Logan wrote:Hello Jose Pedro!
I would like to see the reports created, stored reports and remove the ones I won't use, since I created some for testing. It would just be to clean up the clutter.
The problem is that I don't have all the IDs of the reports already created, so I wanted to list the reports, but the question would be, how to list the IDs of the reports already created
Hello.
Maybe this? https://developer.acronis.com/doc/account-management/v2/guide/usage-rep…
Thanks in advance!
- Log in to post comments

Dear Jose
I really need help with the code, I don't need the documentation link as I have already read it several times. Please take a look at my code and tell me where I am going wrong.
Remarks: I have created several reports, but they are not being created the way I need them to. I have configured it to save, but it creates it as send.
I must have created more than 10 reports, making some test changes, it creates a new report ID, but it's not with the same information that I need.
So I need to find out which reports have already been created. In the link you gave me, it shows how to search for information using the ID, and that is one of my difficulties.
What I need is: To find out which reports have already been created and what their IDs are. Create a report with the options I need.
My Code:
Autentication works fine:
import requests
from base64 import b64encode
import pprint
import json
# Definindo variaveis de autenticação
client_id = '09bbab...' #My ID
client_secret = 'MY SECRET'
datacenter_url = 'https://us-cloud.acronis.com'
# Define uma variável chamada base_url e, em seguida, atribui o valor da datacenter_url a ela e anexa o caminho para a API a essa variável:
base_url = f'{datacenter_url}/api/2'
# Codifica a string client_id e client_secret usando a codificação Base64 e armazena o resultado em uma variável:
encoded_client_creds = b64encode(f'{client_id}:{client_secret}'.encode('ascii'))
# Define uma variável chamada basic_auth e, em seguida, atribui um objeto com a chave Authorization contendo dados de autenticação a esta variável:
basic_auth = {'Authorization': 'Basic ' + encoded_client_creds.decode('ascii')}
# Envia uma solicitação POST para o endpoint /idp/token. A solicitação deve conter dados de autenticação nos cabeçalhos da solicitação e conter o campo grant_type definido como client_credentials em seu corpo:
response = requests.post(
f'{base_url}/idp/token',
headers={'Content-Type': 'application/x-www-form-urlencoded', **basic_auth},
data={'grant_type': 'client_credentials'},
)
# Converte o texto JSON que o corpo da resposta contém em um objeto e, em seguida, armazena este objeto em uma variável chamada token_info:
token_info = response.json()
# Define uma variável chamada auth e, em seguida, atribui um objeto que será usado para construir um cabeçalho de autorização em solicitações da API a esta variável:
auth = {'Authorization': 'Bearer ' + token_info['access_token']}
---------------------------------------------------------------------------------------------------------
Now my code to list the created reports with error 405:
report_list = requests.get(
f'{base_url}/reports',
headers=auth,
)
report_list.text
---------------------------------------------------------------------------------------------------------
My Code to create a new Report:
report_data = {
"parameters": {
"kind": "usage_summary",
"tenant_id": "MY ID",
"level": "all_customers",
"formats": [
"csv_v2_0",
],
"hide_zero_usage": "true",
"show_skus": "true"
},
"schedule": {
"type": "monthly"
},
"result_action": "save"
}
report_data = json.dumps(report_data, indent=4)
new_report = requests.post(
f'{base_url}/reports/',
headers={'Content-Type': 'application/json', **auth},
data=report_data,
)
new_report.text
'{"recipients":[],"result_action":"send","version":1,"schedule":{"enabled":true,"type":"monthly"},"parameters":{"tenant_id":"MY ID","kind":"usage_summary","formats":["csv","html"],"hide_zero_usage":true,"show_skus":true,"period":{"start":"2023-04-01","end":"2023-04-30"},"level":"all_customers"},"generation_date":"2023-05-02","id":"3ff9c129...."}'
This is the returned result. Look:
"result_action":"send"
"send" and not "save" as i wish
"formats":["csv","html"]
And not "csv_v2_0" as i wish
I appreciate your help!
- Log in to post comments

Hello Rafael!
I suggest you in that situation to raise a ticket with our support so they can escalate it to one of our API experts so they can help you with the code.
https://kb.acronis.com/content/8153
If you have any issues during the process, please let me know.
Thanks in advance!
- Log in to post comments