Skip to main content

API - Get a tenants usage by month

Thread needs solution
Beginner
Posts: 2
Comments: 3

Hi all,

is it possible to get the usage of a tenant by month?

The API endpoint /tenants/<id>/usages just shows the latest month. In the json respone I can see a "range_start" parameter. So is there any way to get the usage of a specific month? 

We would like to get this information to automate the billing process for our customers.

Thank you,

Daniel

0 Users found this helpful
Acronis engineer
Posts: 0
Comments: 84

Hello Daniel,

Thank you for your request.

We don't use the GET /usages type of endpoints for Billing purposes. For these endpoints we don't have a range parameter to set a specific period. The "range_start" parameter shows the start date of the current billing period.

Instead please use the only supported method for collecting and reporting usages for Billing purposes via the Usage Reports endpoints. Please, review all about reports starting: https://developer.acronis.com/doc/account-management/v2/guide/usage-rep…

Also, there is a nice Blog article where we showed the whole flow for this specific purpose: https://developer.acronis.com/blog/posts/billing-automation-with-usage-…

The Blog article should best help you developing the automation, but also keep referencing to the official API documentation where all required endpoints are described with their useful parameters.

Thank you!

Beginner
Posts: 2
Comments: 3

Hi Ivaylo,

thank you for the additional information.

I managed to create the api requests and a report was successfuly saved. I can check the status of the report and everything seems to be ok.

For generating the report I used the json structure from the blog article and changed the tenant_id and the period-start and period-end dates.

However it seems that the report is always generated for the current month and not for the period range I have defined in the json.

This is the json I post:

{

    "parameters": {

        "kind": "usage_summary",

        "level": "direct_partners",

        "tenant_id": "<my id>",

        "formats": [

            "csv_v2_0"

        ],

        "show_skus": true,

        "hide_zero_usage": true

    },

    "period": {

        "start": "2022-01-01",

        "end": "2022-01-15"

    },

    "schedule": {

        "type": "once"

    },

    "result_action": "save"

}

 

 

And this is the info I get:

{

    "schedule": {

        "enabled": true,

        "type": "once"

    },

    "version": 1,

    "generation_date": "2022-02-08",

    "recipients": [],

    "id": "<report id>",

    "result_action": "save",

    "parameters": {

        "period": {

            "start": "2022-02-01",

            "end": "2022-02-07"

        },

        "level": "direct_partners",

        "hide_zero_usage": true,

        "kind": "usage_summary",

        "show_skus": true,

        "tenant_id": "<my id>",

        "formats": [

            "csv_v2_0"

        ]

    }

}

 

Do you have any idea why the dates are not set?

 

Thank you

Daniel

Acronis engineer
Posts: 0
Comments: 84

Hello Daniel,

That's an issue, I am able to reproduce it.

We should be able to POST and then GET the report saved for the exact period we specified. I remember it clearly working in the past, which is why I recommended using Reports for this.

Would you mind raising a Support ticket so we can report this to RnD as a real customer issue? Or you can share your company name and any login name from you partner root tenant and I will create a ticket.

Thank you in advance!

Beginner
Posts: 2
Comments: 3

Thank you. I sent you a message with the details.

Acronis engineer
Posts: 0
Comments: 84

Hello Daniel,
 
The problem is that the wrong request format is being used, Dev noticed the problem. The "period" object should be inside the "parameters" object. In the official API documentation, and endpoint details itself, we have the correct Body posted, but in the blog article it is wrong which I guess is the place you took the example from. I reproduced as I directly re-used your Body which was not correct. Better attention to details from the Dev.
 
Correct request:
{
    "parameters": {
        "kind""usage_summary",
        "level""direct_partners",
        "tenant_id""<my id>",
        "formats": [
            "csv_v2_0"
        ],
        "period": {
            "start""2022-01-01",
            "end""2022-01-15"
        },
        "show_skus"true,
        "hide_zero_usage"true
    },
    "schedule": {
        "type""once"
    },
    "result_action""save"
}
 
We will fix the blog article, and Postman public collections where we have this wrong example.
 
Feel free to re-test with the correct Body.
 
Thank you.
Beginner
Posts: 2
Comments: 3

Hi Ivaylo,

I updated the json and now it works. And yes, I took the example code from the blog post.

Is it correct, that I can only generate date ranges within a month and not more than a month?

 

Thank you,

Daniel

 

 

 

 

 

Acronis engineer
Posts: 0
Comments: 84

Hi Daniel,

Not correct, it is possible to specify a custom period longer than a month.

Except for reports where "kind": usage_current which contain the current service usage metrics for the previous day by default and period cannot be specified.

Thank you.