Skip to content

Instantly share code, notes, and snippets.

@Arefu
Last active April 4, 2025 07:37
Show Gist options
  • Save Arefu/74df931c8b6848d6bcdb88fa9a283377 to your computer and use it in GitHub Desktop.
Save Arefu/74df931c8b6848d6bcdb88fa9a283377 to your computer and use it in GitHub Desktop.
Pak 'n Save API Hijinx - Found using Firefox's Inspector tools. There are more, CommonApi presumably means it will also work on New World.
Invoke-WebRequest -UseBasicParsing -Uri "https://www.paknsave.co.nz/" `
-UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:136.0) Gecko/20100101 Firefox/136.0" `
-SessionVariable PaknSave `
-Headers @{
"Accept" = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
"DNT" = "1"
} | Out-Null
$Stores = Invoke-WebRequest "https://www.paknsave.co.nz/CommonApi/Store/GetStoreList" `
-Method Post `
-UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:136.0) Gecko/20100101 Firefox/136.0" `
-UseBasicParsing `
-SessionVariable $PaknSave `
-Headers @{
"Accept" = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
"DNT" = "1"
}
$StoresList = ($Stores.Content | ConvertFrom-Json).stores
$NorthIslandStores = $StoresList | Where-Object { $_.region -eq "NI" }
$SouthIslandStores = $StoresList | Where-Object { $_.region -eq "SI" }
Write-Host "1) North Island (NI)"
Write-Host "2) South Island (SI)"
$Region = ""
$RegionSelection = Read-Host "Please select your region"
if ($RegionSelection -eq "1") {
$Region = "NI"
$SelectedRegionStores = $NorthIslandStores
Write-Host "You selected: North Island (NI)"
} elseif ($RegionSelection -eq "2") {
$Region = "SI"
$SelectedRegionStores = $SouthIslandStores
Write-Host "You selected: South Island (SI)"
}
$Counter = 1
foreach ($Store in $SelectedRegionStores) {
Write-Host "$Counter) $($Store.name)"
$Counter++
}
$StoreSelection = Read-Host "Please select your store by entering the corresponding number"
$StoreID = $SelectedRegionStores[$StoreSelection - 1].id
Write-Host "You selected: $($SelectedRegionStores[$StoreSelection - 1].name)"
Write-Host "Store ID saved: $StoreID"
Write-Host "Getting `"Aisle of Value`""
$PaknSave.Cookies.Add((New-Object System.Net.Cookie("eCom_STORE_ID", "StoreID", "/", "www.paknsave.co.nz")))
$PaknSave.Cookies.Add((New-Object System.Net.Cookie("eCom_StoreId_NotSameAs_Brands", "false", "/", "www.paknsave.co.nz")))
$PaknSave.Cookies.Add((New-Object System.Net.Cookie("brands_store_reset", "", "/", "www.paknsave.co.nz")))
$PaknSave.Cookies.Add((New-Object System.Net.Cookie("STORE_ID_V2", "$StoreID|False", "/", "www.paknsave.co.nz")))
$PaknSave.Cookies.Add((New-Object System.Net.Cookie("Region", "$Region", "/", "www.paknsave.co.nz")))
$PaknSave.Cookies.Add((New-Object System.Net.Cookie("AllowRestrictedItems", "true", "/", "www.paknsave.co.nz")))
$ValueItems = Invoke-WebRequest -UseBasicParsing -Uri "https://www.paknsave.co.nz/CommonApi/Checkout/GetAisleOfValueProducts" `
-WebSession $PaknSave `
-UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:136.0) Gecko/20100101 Firefox/136.0" `
-Headers @{
"Accept" = "application/json, text/plain, */*"
"Accept-Language" = "en-US,en;q=0.5"
"Accept-Encoding" = "gzip, deflate, br, zstd"
"Referer" = "https://www.paknsave.co.nz/"
"DNT" = "1"
}
$Counter = 1
foreach ($Item in ($ValueItems.Content | ConvertFrom-Json).products) {
$Item.name + " is on sale for $" + $Item.price
}
@Arefu
Copy link
Author

Arefu commented Apr 4, 2025

function Get-StoresInformation {
    param(
        [Parameter(Mandatory = $true)]
        [ValidateSet("PakNSave", "NewWorld")]
        [string]$Brand
    )
    
    (Invoke-WebRequest -Uri "https://www.$Brand.co.nz/CommonApi/Store/GetStoreList" -Method Post `
        -UserAgent "(No_User_Agent)" `
        -Headers @{
        "Accept" = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
        "DNT"    = "1"
    }).Content
}

function Set-Store {
    param (
        [Parameter(Mandatory = $true)]
        [Guid]$Store,
        [Parameter(Mandatory = $true)]
        [ValidateSet("PakNSave", "NewWorld")]
        [string]$Brand
    )

    (Invoke-WebRequest -Uri "https://www.$Brand.co.nz/CommonApi/Store/ChangeStore?storeId=$Store&clickSource=list"`
        -UserAgent "(No_User_Agent)" `
        -Method Post `
        -Headers @{
        "Accept" = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
        "DNT"    = "1"
    }).Content
}

function Get-MegaMenuItems {
    param (
        [Parameter(Mandatory = $true)]
        [Guid]$Store,
        [Parameter(Mandatory = $true)]
        [ValidateSet("PakNSave", "NewWorld")]
        [string]$Brand
    )

    (Invoke-WebRequest -Uri "https://www.$Brand.co.nz/CommonApi/Navigation/MegaMenu?v=&storeId=$Store"`
        -UserAgent "(No_User_Agent)" `
        -Method Get `
        -Headers @{
        "Accept" = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
        "DNT"    = "1"
    }).Content
}

function Get-StoreCategories {
    param (
        [Parameter(Mandatory = $true)]
        [Guid]$Store,
        [Parameter(Mandatory = $true)]
        [ValidateSet("PakNSave", "NewWorld")]
        [string]$Brand
    )
    
    $Children = (((Get-MegaMenuItems -Store $Store -Brand $Brand) | ConvertFrom-Json).NavigationList | Where-Object Name -eq "Groceries").Children
    $ProductCategories = @()

    while ($Children -and $Children.Count -gt 0) {
        $ProductCategories += $Children | ForEach-Object { $_.Name }
        $Children = $Children | ForEach-Object { $_.Children } | Where-Object { $_ -ne $null } | Select-Object -ExpandProperty Children -ErrorAction SilentlyContinue
    }

    $ProductCategories | Sort-Object -Unique
}

function Get-ItemsSoldInCategory {
    #https://api-prod.newworld.co.nz/v1/edge/search/paginated/products
    param (
        [Parameter(Mandatory = $true)]
        [Guid]$Store,
        [Parameter(Mandatory = $true)]
        [ValidateSet("PakNSave", "NewWorld")]
        [string]$Brand
    )
}```

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