Skip to content

How to validate barcode scans using Orca Scan and Python

Notifications You must be signed in to change notification settings

orca-scan/orca-validation-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

orca-validation-python

Example of how to validate barcode scans in real-time using Python and flask framework.

Install

First ensure you have Python installed:

macOS or Linux

# should return 3.7 or higher
python3 --version

Windows

# should return 3.7 or higher
python --version

Then execute the following:

# download this example code
git clone https://github.com/orca-scan/orca-validation-python.git

# go into the new directory
cd orca-validation-python

macOS or Linux

# create virtual environment and activate it
python3 -m venv orca && source ./orca/bin/activate

Windows

# create virtual environment and activate it
python -m venv orca && source ./orca/scripts/activate

All

# upgrade pip to latest version
python -m pip install --upgrade pip

# install dependencies
pip install -r requirements.txt

Run

macOS or Linux

# activate virtual environment
source ./orca/bin/activate

Windows

# activate virtual environment
source ./orca/scripts/activate

All

# enable development features only for development
export FLASK_ENV=development

# start the project
flask run -p 5000 

Your server will now be running on port 5000.

You can emulate an Orca Scan Validation input using cURL by running the following:

curl --location --request POST 'http://localhost:5000/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "___orca_sheet_name": "Vehicle Checks",
    "___orca_user_email": "[email protected]",
    "Barcode": "orca-scan-test",
    "Date": "2022-04-19T16:45:02.851Z",
    "Name": "Orca Scan Validation",
}'

Important things to note

  1. Only Orca Scan system fields start with ___
  2. Properties in the JSON payload are an exact match to the field names in your sheet (case and space)

Example

This example uses the flask framework:

Barcode validation

Orca Scan Barcode Data Validation

# POST / handler
@app.route('/', methods=['POST'])
def orca_validation():
    if request.method == 'POST':
        data = request.get_json()

        # debug purpose: show in console raw data received
        print("Request received: \n"+json.dumps(data, sort_keys=True, indent=4))

        # NOTE:
        # orca system fields start with ___
        # you can access the value of each field using the field name (data["Name"], data["Barcode"], data["Location"])
        name = data["Name"]

        # validation example
        if(len(name) > 20):
            # return error message
            return json.dumps({
                "title": "Invalid Name",
                "message": "Name cannot contain more than 20 characters",
                })

        # return HTTP Status 200 with no body
        return '', 200

Test server locally against Orca Cloud

To expose the server securely from localhost and test it easily against the real Orca Cloud environment you can use Secure Tunnels. Take a look at Ngrok or Cloudflare.

ngrok http 5000

Troubleshooting

If you run into any issues not listed here, please open a ticket.

Examples in other langauges

History

For change-log, check releases.

License

© Orca Scan, the Barcode Scanner app for iOS and Android.

About

How to validate barcode scans using Orca Scan and Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages