Creating a new task with requested barcodes

Creating a new task with requested barcodes

Barcode requesting means to create a task that requires barcode data to be completed. This will inform the driver that one or more barcodes should be scanned prior to completing a task. You can optionally block task completion on a per barcode basis.

In order to set up barcodes for a task, you can create a new task or update an existing task by providing the barcodes object array, a top-level task property.

The structure of the object of this array property is as follows:

NameTypeDescription
datastringOptional. Base64 representation of the data encoded within the barcode to be captured, max length of 500 characters
blockCompletionbooleanOptional. Whether the worker must capture this data prior to task completion, defaults to false
{
  "data": "aGVsbG8gd29ybGQh", 
  "blockCompletion": true
}

Having the barcodes object will alert the drivers to scan the required barcodes prior to task completion. Onfleet Driver app will prevent drivers from completing the tasks unless the barcodes with the blockCompletion field set to true are captured.

If you would like to request that any barcode be scanned, regardless of data, you may simply omit the data property in your request.

The following request creates a new task with one mandatory and one optional barcode.

curl -X POST "https://onfleet.com/api/v2/tasks" \
       -u "cd3b3de84cc1ee040bf06512d233719c:" \
       -d '{"destination":{...},
            "recipients":[...],
            "scanOnlyRequiredBarcodes": true,
            "barcodes":[
            	{"data":"aGVsbG8gd29ybGQh","blockCompletion":true},
                {"data":"aG93IGFyZSB5b3U/"}
             ]
            }'
{
  "id": "0VuO6yDq5YrGeZ7NVwUqK8hu",
  //...,
  "barcodes": {
    "required": [ 
      { "data": "aGVsbG8gd29ybGQh", "blockCompletion": true },
      { "data": "aG93IGFyZSB5b3U/", "blockCompletion": false }
    ],
    "captured": [ ]
  },
  //... 
}

📘

Use of scanOnlyRequiredBarcodes

Use the boolean flag of scanOnlyRequiredBarcodes upon task creation to restrict the scanning of non-required barcodes. Learn more about the usage here.