Fetching a usage report

To fetch a usage report

  1. Authenticate to the cloud platform via the Python shell.

    The following variables should be available now:

    >>> base_url  # the base URL of the API
    '<the data center URL>/api/2'
    >>> auth  # the 'Authorization' header value with the access token
    {'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImMwMD...'}
    >>> tenant_id  # the UUID of the tenant to which the token provides access
    'ede9f834-70b3-476c-83d9-736f9f8c7dae'
    
  2. Assign the report_id variable the UUID of a report created via the API or a report found in tenant reports:

    >>> report_id = created_report_id
    >>> report_id
    '20dffb36-d77b-45c6-b2fa-39276e98d5fc'
    
  3. Send a GET request to the /reports/{report_id} endpoint:

    >>> response = requests.get(f'{base_url}/reports/{report_id}', headers=auth)
    
  4. Check the status code of the response:

    >>> response.status_code
    200
    

    Status code 200 means that the request was successful.

    Note

    A different status code means that an error has occurred. For details of the error, see HTTP status response codes and API error codes.

    Also, the response body contains the report data, formatted as a JSON text. When converted to an object, it will look like this:

    >>> pprint.pprint(response.json())
    {'generation_date': '2017-05-08',
     'id': '20dffb36-d77b-45c6-b2fa-39276e98d5fc',
     'parameters': {'formats': ['csv', 'html'],
                     'kind': 'usage_summary',
                     'level': 'accounts',
                     'period': {'end': '2017-05-07', 'start': '2017-05-01'},
                     'tenant_id': 'ede9f834-70b3-476c-83d9-736f9f8c7dae'},
     'recipients': ['ca451758-b48a-45d9-9ae6-8f1059f67619',
                     'ab00e527-219b-481b-b01b-311b5be0ed3c'],
     'result_action': 'send',
     'schedule': {'enabled': True, 'type': 'once'},
     'version': 1}
    
  5. Store the UUID of the report in a variable:

    >>> report_id = response.json()['id']
    >>> report_id
    '20dffb36-d77b-45c6-b2fa-39276e98d5fc'
    
  6. [Optional] Store the revision number of the report, in case if you need to delete it:

    >>> version = response.json()['version']
    >>> version
    1