This project has been tested on my local computer and works for me. As of writing this, I haven't received feedback if it works for others fresh from clone.
Gets current etsy orders and prints shipping label on brother label printer.
See the full etsy API documentation here: https://developers.etsy.com/documentation/ This is useful to understand the auth flow and to understand the env variables: CLIENT_ID, CLIENT_SECRET, SHOP_ID, ACCESS_TOKEN, REFRESH_TOKEN, and SCOPES.
See the full brother-ql library here: https://github.com/pklaus/brother_ql This is useful to understand how your label is going to be printed and to understand the env variables: PRINTER_IP, PRINTER_MODEL, and LABEL_SIZE
- Go to etsy for developers and register your app. (Search the web on how to do that, you will land on the right page in no time).
- In the registering form, mention that you only want to use the app for yourself and that the access will be used sparsely.
- If your app takes a long time to register, contact the etsy developrt support. (Search the web on that aswell).
- When your app is registered you will receive CLIENT_KEY / CLIENT_ID and CLIENT_SECRET_KEY / CLIENT_SECRET which are needed further down.
- Click on your now registered app on etsy, and set the following callback uri: https://localhost:5000/callback
- Make sure your brother label printer is powered on, connected to the internet via the same network as from where you run this script, and has a label roll correctly inserted.
To receive my first ACCESS_TOKEN, REFRESH_TOKEN and SHOP_ID, I used postman. You need two requests. The first one to get ACCESS_TOKEN and REFRESH_TOKEN, the second one to get SHOP_ID. Make sure to set the additional callback URI of postman in the etsy app, as done before for your localhost callback. This all is tricky if you have no or not much coding experience in the area of working with API's. Hit me up if you have trouble with this. Maybe I can do a video on the process in the future. Theoretically all needed info for this is the registered etsy app, the etsy api documentation and the registered postman callback uri in the etsy app.
- Clone directory and open it in the editor of your choice.
- Add a .env file and store the following variables in there:
- CLIENT_ID=client_key_from_your_etsy_app
- CLIENT_SECRET=client_secrect_from_your_etsy_app
- SHOP_ID=your_shop_id (See Postman chapter in this docu, just above.)
- ACCESS_TOKEN=your_access_token (See Postman chapter in this docu, just above.)
- REFRESH_TOKEN=your_refresh_token (See Postman chapter in this docu, just above.)
- SCOPES=your_scopes_according_to_etsy_docu (For this script to work it is transactions_r.)
- PRINTER_IP=ip_from_brother_label_printer
- PRINTER_MODEL=name_of_your_printer_according_to_brother_ql_docu
- LABEL_SIZE=label_size_in_your_printer_according_to_brother_ql_docu (It's the column with "29x90" and similar entries.)
- LABEL_WIDTH=pixel_label_width_in_your_printer_according_to_brother_ql_docu
- LABEL_HEIGHT=pixel_label_height_in_your_printer_according_to_brother_ql_docu
- FONT_SIZE=120 (Trial and error, there's logic that adjusts font size automatically a bit.)
- BACKEND=network (Check brother-ql docu on how to use USB, I never used it.)
- REDIRECT_URI=https://localhost:5000/callback (As mentioned earlier, make sure you have the same URI saved in your etsy app.)
- FLASK_SECRET_KEY=random_string_of_characters (Choose your own length.)
- Open a Terminal in the project directory and run the following commands:
- Install the necessary venv via something like: python3 -m venv venv or python -m venv venv
- Source the virtual environment. On Linux/Mac it usually is: source ./venv/bin/activate On Windows it usually is: .\venv\Scripts\activate
- Install the necessary requirements to run the script: pip install -r requirements.txt
- In your created .env file, make sure you adjust your label size, label pixels according to brother-ql documentation readme.
- Adjust font size in the main print script. (Had to figure this one out iteratively).
- Make sure you have openSSL installed on your system, cd into the cert folder of this project and run: ´openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365 -subj "/CN=localhost"´
If you have set up everything correctly, you will now have in addition to what you had initially in the folder:
- A .env file with the following content:
- CLIENT_ID
- CLIENT_SECRET
- SHOP_ID
- ACCESS_TOKEN
- REFRESH_TOKEN
- SCOPES
- PRINTER_IP
- PRINTER_MODEL
- LABEL_SIZE
- LABEL_WIDTH
- LABEL_HEIGHT
- FONT_SIZE
- BACKEND
- REDIRECT_URI
- FLASK_SECRET_KEY
- cert.pem and key.pem in the cert folder.
Run ´python print_shipping_labels.py´ to print all shipping labels for all orders that are unshipped and paid.