In case anyone else is interested, this is the code I created in Python:
#!/usr/bin/env python3
import httpx
import json
def update_number( type, status ):
# --- HTTP REQUEST
# the BASE URL for EXPENSES
base_URL = 'https://invoicing.co/api/v1/' + type
headers = {
'X-API-Token': YOUR_API_KEY_HERE
,'X-Requested-With': 'XMLHttpRequest'
,'Content-Type':'application/json'
}
# URL parameters
parameters = {
'per_page': 1000
,'sort': 'date|asc'
,'status': status
}
# connect to API with the HEADERS and PARAMETERS already declared
response = httpx.get( base_URL, headers=headers, params=parameters )
# convert data fron JSON to a Python array
response = json.load( response )
# copy and thereby decrease 1 level of the multi-dimensional array data
expense_data = response['data']
# count the quantity of rows/records retrieved in the previous API call
count = len( expense_data )
if count < 1:
exit('No records were retrieved.')
print( 'Quantity: ' + str(count) )
# Loop through each record retrieved from the previous API call
i = 1
for x in expense_data:
prefix = ''
# --- NOW let's loop through each one and update the number
if i < 10:
new_number = prefix + '.000' + str(i)
elif i < 100:
new_number = prefix + '.00' + str(i)
elif i < 1000:
new_number = prefix + '.0' + str(i)
else:
new_number = prefix.str(i)
URL = base_URL + '/' + x['id']
data = {'number': new_number }
response = httpx.put( URL, headers=headers, json=data )
print( 'Post result: ' + response.text )
i = i + 1
# --- END of the UPDATE_NUMBER function
# function arguments
'''
1st argument options:
clients, products, invoices, recurring_invoices, payments, quotes, credits,
projects, tasks, vendors, purchase_orders, expenses, recurring_expenses,
bank_transactions, reports, activities, companies, company_users,
expense_categories, subscriptions, system_logs
2nd function argument:
active|archived. NOTE: 'deleted' items cannot be modified.
'''
# call the function and specify the type and status
update_number( 'expenses', 'archived' )