A small collection of python scripts to perfom actions on a Rackbeat inventory.
In its simple form, it's an easy way to perform automated tasks through the Rackbeat API.
Its intented for use on Windows, but the python scripts themselves should work regardless of OS.
- Create Product Groups
- Create Unit Types
- Import products
- Import changes to existing product
- Create credit note from invoice no.
- Convert a product to a LOT/Bill Of Material
- Unbook a booked invoice
- Update products (like the "Update existing" option from the UI)
- Update customer:
- Add discount groups
- Migrate un-importable data like:
- Customer contacts
- Customer delivery addresses
- Update specific product information:
-
- Default department ID (only e-conomic customer has this field)
- Product Group
- Sales Price
- Supplier Product Number
- Set "Adjust negative quantity to 0" for all BOMs/Lots (BULK)
- Bulk delete:
- Contacts in E-conomic (requires additional e-conomic API key!)
- Customer delivery addresses
- Unit types
The toolbox scripts are made in Python, which is of course required.
They also depend on different libraries to function as well. A install script has been provided in install-toolbox-deps.ps1
, that will verify that python
, pip
and the nessecary python libraries are available. To run this, your user needs to have a unrestricted
execution policy. If you are able to run scripts, you can skip step 2:
- Open a Powershell terminal
Click the start menu, and typePoweshell
and click theRun as administrator
option. - Set the Powershell execution restrictions as
unrestricted
*
Typeset-executionpolicy unrestricted
in the terminal and hitEnter
Verify the action withY
when prompted - Make sure
git
is installed and can be executed
Typewinget install Git.Git
, hitEnter
- Restart the terminal
Simply close it, and reopen it, like in step 1, and continue - Clone this Github repo locally with the command:
copy the following commandgit clone https://github.com/mikkelrask/rackbeat-tools.git
and paste it to the terminal withCTRL
+Shift
+V
followed byEnter
- Navigate into the local repo
typecd rackbeat-tools
and pressEnter
- Install requirements and dependencies with:
& .\install-toolbox-deps.ps1
This will install the latest verion of python
, pip
and the libraries requests
and python-dotenv
*More information about the execution policy and options regarding that, can be found here: https://windowsloop.com/enable-powershell-scripts-execution-windows-10
When new tools are added, or current ones are updated, you can update your repo to get the latest changes. When in your project folder, open a Terminal (i.e Right click, and click "Open in Terminal")
Type git pull
and hit Enter
.
Your local repo is now updated with the latest changes.
To use the utilities, you need to provide a valid API key as your Bearer
token to be able to make requests.
This token acts as a password to ensure that you have the privilege to perform actions on the account. API keys are personal, and all actions performed with the utilities will be linked to the user who created it.
To generate an API key, follow these steps:
- Go to app.rackbeat.com/settings/api.
- Click the
Create new
button. - Give the API key a fitting name.
- Confirm the creation of the new API key by clicking
Create new
.
After generating the API key, you will receive a base64url encoded JSON key, which should look like this:
It should provide you with a base64url encoded json like this (no worries, this isnt an active key)
Please note that the API key will not be displayed again, so make sure to store it properly.
To make sure that you don´t have to edit and save all utils with the correct Bearer token on each run, an environment file has been created, which all utilities then refers to, when looking for the API key.
To use the API key in your Python project, follow these steps:
- Locate the
.env
file in the root folder of your project. - Copy and paste the generated API key between the quotes of the
BEARER_TOKEN
, like this:
BEARER_TOKEN="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIzIiwianRpIjoiYzRhODIwNWRiNTJlMGU3NGVkODRhNjk0MjY4YWE4MDQ5MDQzNzY2MTFlNWQ5YmU3ZDVlMTY2NGQ2ZDgzMGQ2ODNiNzc5ZDA3MTgxZWE0NjIiLCJpYXQiOjE2ODc1OTc3MjAuMjc3MDMzLCJuYmYiOjE2ODc1OTc3MjAuMjc3MDM3LCJleHAiOjIwMDMyMTY5MjAuMjY1Mzk2LCJzdWIiOiIxNTM1NSIsInNjb3BlcyI6W119.DY_cZP-bpRZTGVOEAZwehmuSWsZVozSfW8QPeMZyVveeTvzB6TML9TkNRut_fYjiJ5uQvsN7MQcv7XjSiRnCT89Latx70Cq1qGqf6BtEVWwvMlO90nWwL7LBfCOwHADQMyRMsBEOpMKXfPiTSbY6CAYAEhn26BCfsi24Qh_1xSb-wMhqxaHkk2_9S9nh8KXlxpbDVCrpGMS04aUVcVudzVztSbjoIjNlsCPO8H8TD4VfqcV9zbKQy3IAe-1eUPTdilQaty2vbK-vl0qsSLvIT32SiY-fAtTu8Ya7_x5xZKG5Hpfw1ol1PBjHfrD2NH1xqLacCyGmynna7HAAFV5xNoNKhoP-tHvh1ZW0PnJP5iXHr9O0FYEidIqm0YSwqP7V43O1m1hkRnnvfEFxwZMwya8W81f1JbmDJSOUv2iKnbKAR4lUvmggpAB7S4OvRUWD5_V8uScyVynDO07CJKfwEhKttfKpAbAzQeHBCtYqa5HdpGpy4vRqfvm4rGeA2VNAEtz1uV4KT-Dw9dIwYMb20sGw2Vm-vNvx3-qNlJq2WJlTaCd5gnajN3TS8ZjATMrTdylbLXmj9cuJFf0N8nBL8C_IfkYGXgwWez_XrF6Wq43NFgeY69N1cFrX7K-b--9ZKUoZU5He0y7FrTraXKXfdOviu2Z7hSXDPejtJXhrhZI"
(no worries, this is **not** an active key)
- Save the file.
For each customer, start out by creating a copy of the import-template.csv
file. This file has custom named table headers, that the import/update scripts map with what the API endpoints expects. To prevent mishaps, when managing multiple Rackbeat accounts, sticking to a naming convention i.e like {account}-{date}.csv
, could help minimize wrongful imports, but has no other function than that.
- Open the
.env
file again - Put the import files local path in the
IMPORT_FILE
variable in the.env
file. So if the import file was located in the same directory as eht.env
file, it would look like this:
IMPORT_FILE="./7235-24062023.csv"
- Save the
.env
file.
To run the toolbox, execute the RB-Toolbox script:
- Open the Repo folder in your File Explorer
- Right click the folder and click
Open in Terminal
- Type
python .\RB-Toolbox.py
and pressEnter
. - Follow the instructions on the screen.
Please always remember to verify the company and agreement number, shown in the top! Each functionality can be executed individually without the "Toolbox Menu". See below options
With the Bearer token set in the .env
file, often times the first thing youd want to do is to quickly create some item/product groups.
- Execute
python .\create-groups.py
in a terminal emulator. - Fill out
Group name:
when prompted - Fill out
Group ID:
when prompted - Fill out VAT informations for domestic, EU, abroad and domestic tax-exempt
- Set weather the products in this group has an inventory
- Set weather the products in this group are able to be sold (y/n)
- Execute
python .\create-unit-types.py
in a terminal emulator. - Fill out
Unit ID:
when prompted - Fill out
Unit Name:
when prompted
Your unit type is now created.
With both the .env
file populated, and and the groups
and unit types created, we are ready to rock and/or roll!
python .\import-products.csv
will look in the .env
file for the BEARER_TOKEN
/api key and what file it needs to process.
Note! This script iterates through each line of the csv file, creating the products one by one. This can potentially be a lot of calls, and is not at all effecient. But it does make sure we don´t hit any speed limits, just as it will still create what ever products it can from the import sheet, rather than to abort the complete import if theres was found an error on one or more of the lines in the product sheet. The lines that wasnt importable will be skipped, and an exlanation/error message will be output in the terminal window.
When products have been populated to your Rackbeat inventory, sometimes minor changes are needed. Make multiple of those, by importing product updates.
- Edit the
7235-24062023.csv
file (or whatever your import file was named) with the wanted changes - execute
python update-products.py
- ...?
- Profit! 🤑