Last active
October 5, 2020 15:45
-
-
Save monaboiste/27aad9b6881758a6c44d5049b251b12d to your computer and use it in GitHub Desktop.
InPost ParcelTracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Generates .TXT/CSV file with tracking status for given parcels. | |
.DESCRIPTION | |
For given .CSV file, generate a .TXT/CSV file with tracking status. | |
Script only supports API SHIPX (Paczkomaty PL). | |
Input .CSV file HAS TO be in format: | |
ID (Titles) | |
Ids enteret in columna, e.g. | |
| Ids | | |
+----------------------+ | |
| 00340434292135100094 | | |
| 00340434292135105255 | | |
| ... | | |
.PARAMETER CSVFilePath | |
Path to CSV file. | |
.INPUTS | |
None. You cannot pipe objects to this script. | |
.OUTPUTS | |
szumna.txt in CSV format contains Tracking Status. | |
If Status equals 0, then parcel's ID must be wrong | |
or tracking is inactive. | |
.LINK | |
None. | |
.EXAMPLE | |
.\Track-Parcels.ps1 -CSVFilePath "full-path-parcels-ids.csv" | |
#> | |
<# Some API's to explore: | |
# DHL https://api-gw.dhlparcel.nl/track-trace?key=7777777770 | |
# https://api-eu.dhl.com/track/shipments?trackingNumber=00340434292135100094 | |
# https://api-gw.dhlparcel.nl/docs/#/track-trace/getTrackAndTrace | |
#> | |
Param ( | |
[Parameter(Mandatory=$True)] | |
[ValidateNotNullOrEmpty()] | |
[String]$CSVFilePath | |
) | |
$TrackingAPI = "https://api-shipx-pl.easypack24.net/v1/tracking/" | |
$ParcelIds = (Get-Content "$CSVFilePath") | |
$Parcels = @() | |
Trap [Net.WebException] { continue; } | |
For ($i = 1; $i -lt $ParcelIds.Count; $i++) { | |
$Id = $ParcelIds[$i] | |
$Details = @{} | |
Try { | |
$Response = Invoke-RestMethod -Uri $TrackingAddr$Id -ContentType "application/json" | |
$Details = @{ | |
"Courier" = "PL - InPost"; | |
"TrackingID" = $Id; | |
"Status" = $Response.Status | |
} | |
} Catch { | |
$StatusCode = [UInt32]$Error[0].exception.Response.statuscode.value__ | |
$Details = @{ | |
"Courier" = "PL - InPost"; | |
"TrackingID" = $Id; | |
"Status" = "Status: $StatusCode" | |
} | |
} | |
$Parcels += New-Object PSObject -Property $Details | |
} | |
$Parcels | ConvertTo-Csv -NoTypeInformation | Out-File szumna.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment