Example of how to validate barcode scans in real-time in C# using ASP.NET Core.
git clone https://github.com/orca-scan/orca-validation-dotnet.git
cd orca-validation-dotnet
dotnet restore
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"
}'
- Only Orca Scan system fields start with
___
- Properties in the JSON payload are an exact match to the field names in your sheet (case and space)
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("");
}
}
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
If you run into any issues not listed here, please open a ticket.
- orca-validation-dotnet
- orca-validation-python
- orca-validation-go
- orca-validation-java
- orca-validation-php
- orca-validation-node
For change-log, check releases.
© Orca Scan, the Barcode Scanner app for iOS and Android