Skip to content

orca-scan/orca-validation-dotnet

Repository files navigation

orca-validation-dotnet

Example of how to validate barcode scans in real-time in C# using ASP.NET Core.

Install

git clone https://github.com/orca-scan/orca-validation-dotnet.git
cd orca-validation-dotnet
dotnet restore

Run

dotnet run

Your server will now be running on port 3000.

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

curl --location --request POST 'http://localhost:3000/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "___orca_sheet_name": "Vehicle Checks",
    "___orca_user_email": "hidden@requires.https",
    "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)

How this example works

A simple ASP.NET Core controller that listens for HTTP POSTS.

[ApiController]
[Route("/")]
public class OrcaValidationDotNet : ControllerBase
{
    [HttpPost]
    [Consumes("application/json")]
    public async Task<ActionResult> validationReceiver()
    {
        using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
        {  
            // get the raw JSON string
            string json = await reader.ReadToEndAsync();

            // convert into .net object
            dynamic data = JObject.Parse(json);

            // NOTE:
            // orca system fields start with ___
            // you can access the value of each field using the fieldname (data.Name, data.Barcode, data.Location)
            string name = (data.Name != null) ? (string)data.Name : "";

            //validation example
            if(name.Length > 20){
                //return json error message
                return Ok(new {
                    title = "Name is too long",
                    message = "Name cannot contain more than 20 characters"
                });
            }
        }

        // return HTTP Status 200 with no body
        return Ok("");
    }
}

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 3000

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 .Net

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages