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 4 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: 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

  • Execute the script with the CSV file as a parameter: python3 script.py test1.csv

  • You will see if the script is working if it’s displaying the response code 201

  • If the file is too big ex. sample file contains 3000 customersID, what can we do is divide the file into 3
    Ex. sample1.csv, sample2.csv, and sample3.csv -each .csv file now contains 1000customer each, then you can run the script for the 3 .csv:
    python3 script.py sample1.csv
    python3 script.py sample2.csv
    python3 script.py sample3.csv

  • The script will create another file once executed, .csv_error and .csv_success
    if there are errors you will see the errors on the .csv_error file and you see all success on .csv_success

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

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.