Updating a usage report

Important

Only scheduled reports can be updated.

To update 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. Fetch the UUID of the report that you want to update as described in Fetching a usage report. As the result, the following variable with the report UUID should be available:

    >>> report_id
    '20dffb36-d77b-45c6-b2fa-39276e98d5fc'
    
  3. Define a variable named report_data, and then assign the report data to update to this variable:

    >>> report_data = {
    ...     "recipients": [
    ...         "ca451758-b48a-45d9-9ae6-8f1059f67619"
    ...     ],
    ...     "parameters": {
    ...         "kind": "usage_current",
    ...         "level": "direct_partners"
    ...     }
    ... }
    

    Name

    Value type

    Required

    Description

    recipients

    array of UUID strings

    No

    An array of UUIDs of the users who should receive the report by email. Must be used only when result_action is set to send

    parameters

    report parameters object

    Yes

    An object of report parameters which allow to configure the report. Only kind and level parameters can be changed.

  4. Convert the report_data object to a JSON text:

    >>> report_data = json.dumps(report_data, indent=4)
    >>> print(report_data)
    {
        "recipients": [
            "ca451758-b48a-45d9-9ae6-8f1059f67619"
        ],
        "parameters": {
            "kind": "usage_current",
            "level": "direct_partners"
        }
    }
    
  5. Send a PUT request with the JSON text to the /reports/{report_id} endpoint:

    >>> response = requests.put(
    ...     f'{base_url}/reports/{report_id}',
    ...     headers={'Content-Type': 'application/json', **auth},
    ...     data=report_data,
    ... )
    
  6. Check the status code of the response:

    >>> response.status_code
    200
    

    Status code 200 means that the report has been successfully updated.

    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_current',
                     'level': 'direct_partners',
                     'period': {'end': '2017-05-07', 'start': '2017-05-01'},
                     'tenant_id': 'ede9f834-70b3-476c-83d9-736f9f8c7dae'},
     'recipients': ['ca451758-b48a-45d9-9ae6-8f1059f67619'],
     'result_action': 'send',
     'schedule': {'enabled': True, 'type': 'once'},
     'version': 1}