Skip to content

Instantly share code, notes, and snippets.

@meduzen
Last active October 20, 2023 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meduzen/b9908a5d3a68737c881fc85f25b5ed4b to your computer and use it in GitHub Desktop.
Save meduzen/b9908a5d3a68737c881fc85f25b5ed4b to your computer and use it in GitHub Desktop.
Run this in the browser console on https://track.bpost.cloud ; don’t forget to update the first 3 lines.
const trackingCode = '324567890'
const postCode = 1000
const language = 'EN' // 'FR', 'NL', 'EN'
let status = null
let deliveryWindow = null
setInterval(() => {
fetch('https://track.bpost.cloud/track/items?itemIdentifier=' + trackingCode + '&postalCode=' + postCode)
.then(res => {
res.json().then(async data => {
status = data.items[0].events
let innerHtml = ''
// Sender
const sender = data.items[0].senderCommercialName ?? data.items[0].sender?.name
innerHtml += `<small>📦 ${sender}</small>`
// Status time and message
innerHtml += `<span id="last-status">${status[0].time}<br>${status[0].key[language].description}`
// Stops left
if ('expectedDeliveryTimeRange' in data.items[0]) {
const res = await fetch(`https://track.bpost.cloud/track/itemonroundstatus?itemIdentifier=${trackingCode}&postalCode=${postCode}`)
const data = await res.json()
if ('itemOnRoundStatus' in data) {
const stopsLeft = data.itemOnRoundStatus.nrOfStopsUntilTarget[0]
innerHtml += `<strong> – ${stopsLeft} stops left</strong>`
}
}
innerHtml += `</span>`
// Delivery window
if ('expectedDeliveryTimeRange' in data.items[0]) {
const deliveryWindow = data.items[0].expectedDeliveryTimeRange
innerHtml += `
<div id="time">
<div>
Now<br>
<span>${(new Date()).toTimeString().substring(0,5)}</span>
</div>
<span id="delivery-window">
Delivery range<br>
<span class="time">${deliveryWindow.time1} - ${deliveryWindow.time2}</span>
</span>
</div>
`
}
// Update HTML
DOM.innerHTML = innerHtml
})
})
}, 3000)
document.body.innerHTML = `
<style>
#app {
display: flex;
flex-direction: column;
justify-content: center;
padding: 0.5em;
text-align: center;
font-size: 7vmin;
height: 100vh;
background-color: #232323;
color: #c1c1c1
}
#output {
margin: 0.5em 0;
min-height: 100%;
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
}
#time {
display: flex;
justify-content; space-evenly;
}
#delivery-window {
margin-left: 1em;
border: 1vmin solid orange;
border-radius: 0.25em;
}
.time {
margin: 0 .5em;
padding-bottom: 5vmin;
font-size: 9vmin;
}
</style>
<div id="app">
<p id="output"></p>
</div>
`
const DOM = document.getElementById('output')
@meduzen
Copy link
Author

meduzen commented Apr 1, 2021

Updated for bpost new API

@meduzen
Copy link
Author

meduzen commented Jul 16, 2021

Updated with delivery time frame. Below screenshots: before - after.

image

image

@meduzen
Copy link
Author

meduzen commented Oct 7, 2021

Updated to include sender and the current hour in addition to the delivery timeframe.

image

image

@meduzen
Copy link
Author

meduzen commented Nov 3, 2021

Fixed sender name being undefined when it has no commercial name.

@meduzen
Copy link
Author

meduzen commented Feb 22, 2022

Now they provide real-time geo for their delivery truck, with a pin on a map (using <canvas>) refreshed every 30 sec. using the following endpoint: https://track.bpost.cloud/track/itemonroundstatus?itemIdentifier=1234567890&postalCode=1234

endpoint sample (anonymized)
{
    "xmlns": [
        "http://schema.post.be/dis/item-on-round-status"
    ],
    "estimatedDeliveryTimeWindow": [
        ""
    ],
    "lastKnownLocation": [
        {
            "long": [
                "1.23456"
            ],
            "lat": [
                "1.23456"
            ]
        }
    ],
    "targetLocation": [
        {
            "long": [
                "1.23456"
            ],
            "lat": [
                "1.23456"
            ]
        }
    ],
    "nrOfStopsUntilTarget": [
        "18"
    ],
    "progressUntilTarget": [
        "-6.738544474393531E-4"
    ]
}

@meduzen
Copy link
Author

meduzen commented May 12, 2023

Now updated to add stops left when it’s out for delivery:

image

@meduzen
Copy link
Author

meduzen commented Oct 20, 2023

Update: can now show basic data when the number of stops left is not know, yet. Before, it was showing an empty screen until the stops left appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment