Skip to end of banner
Go to start of banner

Apply the extra days script

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

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

  • Create a .csv file and put all the CustomersID that you need to add ontime.
    1. CSV file with the account id as the first column of each line. All other columns will be ignored.
    2. The first line will be processed as any other line (so it should not be a header containing the labels, but contain an account as the others).
    3. Sample .csv file here:

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

  • To be configured before each execution

  1. Amount: the amount of time that will be added

  2. custapi_location: Target NGU (here is BDRC)

  3. token: Get your Authorization token in https://authapi.bboxx.co.uk/v1/docs/#/authentication/authenticate This token will be used by the script

  4. Set the token in the python script

  5. Execute the script with the CSV file as a parameter

#!/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()

  • No labels