Predict an order's delivery date
General
To predict an order's delivery date we will use the fetchPrediction
method that:
- calls the Shipup API using the machine learning model
- populates HTML elements that match shipup data-attributes or the custom css selector
- returns the API response
You will find below different examples of usage of the fetchPrediction
method and the reference definition
Examples
Simple
ShipupETA.init({ publicApiKey: 'my-api-key' }).fetchPredictions()
.then(predictions => {
console.log('Predictions', predictions);
})
.catch(error => {
console.error('Error', error)
})
Override default parameters
You can also override the default request payload by specifying it:
ShipupETA.init({ publicApiKey: 'my-api-key' }).fetchPredictions({
destination: {
country_code: 'FR',
},
carriers: [
{
service_code: 'base',
code: 'ups',
},
],
})
.then(predictions => {
console.log('Predictions', predictions)
})
.catch(error => {
console.error('Error', error)
})
Using shipup data attributes
Note that when the carrier_service you want to obtain predictions for is the 'base' carrier_service for the carrier, you'll set the carrier_code as value for the data-attribute instead of 'base' (we have data-shipup-eta-carrier-service="colissimo"
in the example below). For all other carrier services, use the carrier service_code as defined in the documentation.
<div>
Mondial relay : <span data-shipup-eta-carrier-service="mondial_relay">loading...</span>
</div>
<div>
Colissimo : <span data-shipup-eta-carrier-service="colissimo">loading...</span>
</div>
<script>
ShipupETA.init({ publicApiKey: 'my-api-key' }).fetchPredictions()
</script>
ShipupETA.fetchPredictions(options)
Use ShipupETA.fetchPredictions(options)
to estimate an order's arrival date.
Returns Promise<PredictionResult []>.
Additionally, fetchPredictions
will find all DOM nodes that match the data-shipup-eta-carrier="carrier_name"
rule or that match the carrierCodesCssSelectorsMapping
defined for this carrier and replace their inner HTML by the estimated date of arrival in the DOM, using the language configured in the language
parameter of ShipupETA.init
method.
Options input:
FIELD | DESCRIPTION |
---|---|
options.origin address, optional | Package shipping origin (e.g. warehouse location) |
options.destination address, optional | Package destination address (e.g. recipient address).ShipupETA.destinationAddress will be used if not provided |
options.carriers carrier[], optional | List of carriers and services to return predictions for. By default, all carriers added on your Shipup account will be used if not provided. |
options.order order, optional | Order specific details. |
Updated over 1 year ago