The purpose of this script is to Manually add ontime of hundreds of users using Bboxx API.

Prerequisite: Python 3 above.

To run this script, CSV file is needed(parameters for the script/customers that will get the ontime)

-You can get the list of CustomerId per shop on CRM>Application>AdvanceFilter, in this case, Goma shop

Important:
If all devices that receive time should be enabled, the NGU should be configured to enable devices with the specified time that's being added to the accounts. This will also affect other customers.(CRM>Settings>Payment and Gracetime>Minimum payment time)

  1. amount: Set the variable amount of the script to the desired time in seconds that would like to be given by this script.

  2. custapi_location: Set the variable custapi_location to the base URL of customerAPI to be used. It should include domain, version and GEIC.

  3. token: Obtain a token for the user that will be used to issue the time. Please note that the token should be issued by an authentication service of the specific stage (prod, staging, dev), and if using the docs to generate the token, you should ensure you're doing the request to the correct server (example: by specifying '/v1/' in servers)

  4. Get your Authorization token in https://authapi.bboxx.co.uk/v1/docs/#/authentication/authenticate

  5. Set the token in the python script

#!/usr/bin/env python3
import csv
import sys
import requests

# To be configured before each execution
amount = 5 * 3600 * 24
custapi_location = 'https://customerapi.bboxx.co.uk/v1/BDRC'
token = ''


input_fname = sys.argv[1]
input_file = open(input_fname, 'r')
success_data = open(f'{input_fname}_success', 'w', buffering=1)
error_data = open(f'{input_fname}_error', 'w', buffering=1)

input_data = csv.reader(input_file)
for i in input_data:
    payload = {
        'amount': amount,
        'type': 'manual',
        'reason': 'other'
    }
    account_id = i[0]
    headers = {'Authorization': f'Bearer {token}'}
    request_url = f'{custapi_location}/accounts/{account_id}/payg_transactions'
    r = requests.post(request_url, json=payload, headers=headers)
    print(account_id, r.status_code)
    if r.status_code >= 200 and r.status_code < 300:
        success_data.write(account_id+'\n')
    else:
        error_data.write(account_id+','+str(r.status_code)+'\n')
success_data.close()
error_data.close()