1. Inferences
  2. Shipping Label Inference

Inferences

Shipping Label Inference

You can have the inference via the API or the vision-SDK while the vision-SDK will do the network request for you, the responses from this document will remain the same.

New Inference

POST
`/v1/inferences`

To create a new inference for shipping-labels, you'll need to pass the image_url as a base64 encoded data URL or public web URL. There's a soft cap of about 7.5MB per image for the base64 URL.

You're also able to specify what type of image the parser is looking at, so it can better extract data accurately along with other helpful information listed below:

image_url string (required)
Base64 encoded data URL.

barcode_values Array.<String>
Any existing values you've already extracted from the barcode.

location_id String
The ID of the location you want to attribute to this scan.

options Object
Option contains different other optional parameters you can provide along with the image. Those parameters are described below

Show Details

match Object
All the options associated with matching contacts logic.
(These parameter are only required if you are using contact matching)

Show Details
location Boolean
This option will be utilized if you wish to match the extracted sender and recipient fields with existing contacts in your organization. The parameter is a boolean that specifies whether to conduct the matching within this specific location or across the entire organization.
search_score_threshold Number
The matching score refers to the degree of similarity between the contact being matched and the existing contacts. Scores range from 0 to 1, where 1 indicates a perfect match. By default, the score is set to 0.8.
search Array.<String>
It will be a list containing possible values of 'sender', 'recipient', or both. This specifies whether the matching process should target the recipient, the sender, or both fields.

postprocess Object
Optional postprocessing parameters

Show Details
require_unique_hash Object
If this property is set to true, it compares package hashes to determine if a package is a duplicate. If the hashes match, the package will be marked as a duplicate. By default, this property is set to true.
parse_address Array.<String>
It will be a list containing possible values of 'sender', 'recipient', or both. This specifies whether the extracted sender and recipient addresses should undergo parsing by the address parser.

tracker Object
This parameter is optional and serves to track the package. It is only required if you intend to create a tracker object. If you are using the OCR API only, you do not need to specify these parameters.

Show Details
create_automatically Boolean
Boolean specifying whether to create a tracker object automatically or not, it's default to false.
status String
Different status options available with tracker object. Possible options are provided here
use_existing_tracking_number String
To use the same tracking number for tracking of packages as printed on the label. Otherwise PackageX will assign a new tracking number for keeping track of it. It's defaults to true.
type String
The type parameter can take one of two values: "inbound" or "outbound." Use "inbound" if the package is being scanned at the destination location, and "outbound" if it is scanned at the source location.

chained_status TrackingStatusOutstanding

options?.tracker?.chained_status

        enum TrackingStatusOutstanding {
  provider_at_pickup
  package_accepted
  out_for_delivery
  provider_at_dropoff
  scheduled
  driver_dispatched
  package_at_waypoint
  in_transit
  pickup_available
  recipient_at_pickup
  added_to_container
  removed_from_container
  added_to_vehicle
  removed_from_vehicle
  delivered_to_provider
}

      

auto_close_shipments_option TrackerCloseShipmentsOption

options?.tracker?.auto_close_shipments_option

This option determines how to handle outstanding shipments: on_provider_updates: Outstanding shipments will be closed only when the provider sends a tracking update to the shipment. on_all_updates: Outstanding shipments will be closed on any tracking update to the shipment. off: Outstanding shipments will be ignored.

Default: on_provider_updates

        enum TrackerCloseShipmentsOption {
  on_provider_updates
  on_all_updates
  off
}

      

auto_close_shipments_status TrackerCloseShipmentsStatus

options?.tracker?.auto_close_shipments_status

When on_all_updates or on_provider_updates is active, you can select the following completed non-exception statuses for outstanding shipments:

        enum TrackerCloseShipmentsStatus {
  delivered
  picked_up
}

      

js
        const data = {
  image_url: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASA...", //truncated
  barcode_values: [], //If you have already extracted any barcode values from a shipping label
  location_id: null, //You an optionally pass the location ID to later filter scans by location
  options: {
    tracker: {
      status: "pickup_available",
      create_automatically: false,
      type: "inbound",
      chained_status: "in_transit",
      auto_close_shipments_option: "on_all_updates",
      auto_close_shipments_status: "picked_up",
    },
    postprocess: {
      parse_addresses: ["sender", "recipient"],
    },
    match: {
      location: false,
      search: ["recipient"],
    },
  },
};

const res = await fetch("https://api.packagex.io/v1/inferences/images/shipping-labels", {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
}).then((res) => res.json());

const scan = response.data;