# ===============================
# Amazon SP-API Lieferzeit in PowerShell
# ===============================
# === KONFIGURATION ===
# https://sellercentral-europe.amazon.com/apps/manage
$awsAccessKey = "DEIN_AWS_ACCESS_KEY"
$awsSecretKey = "DEIN_AWS_SECRET_KEY"
$region = "eu-west-1"
$host = "sellingpartnerapi-eu.amazon.com"
$lwaClientId = "DEIN_LWA_CLIENT_ID"
$lwaClientSecret = "DEIN_LWA_CLIENT_SECRET"
$lwaRefreshToken = "DEIN_LWA_REFRESH_TOKEN"
$marketplaceId = "ATVPDKIKX0DER" # z.B. US Marketplace
$asin = "B08N5WRWNW" # Produkt-ASIN
# === 1️⃣ LWA TOKEN HOLEN ===
$body = @{
grant_type = "refresh_token"
client_id = $lwaClientId
client_secret = $lwaClientSecret
refresh_token = $lwaRefreshToken
}
$tokenResponse = Invoke-RestMethod -Method Post -Uri "https://api.amazon.com/auth/o2/token" -Body $body
$lwaToken = $tokenResponse.access_token
Write-Host "LWA Token erhalten."
# === 2️⃣ AWS SIGNATURE V4 ERSTELLEN ===
# Hilfsfunktion Signatur erstellen
function Get-AWSSignature {
param (
[string]$method,
[string]$service,
[string]$region,
[string]$host,
[string]$uri,
[string]$payload
)
$t = Get-Date -Format "yyyyMMddTHHmmssZ"
$date = $t.Substring(0,8)
$algorithm = "AWS4-HMAC-SHA256"
# Payload Hash
$payloadHash = [System.BitConverter]::ToString((New-Object Security.Cryptography.SHA256Managed).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($payload))).Replace("-", "").ToLower()
# Canonical Request
$canonicalRequest = "$method`n$uri`n`nhost:$host`nx-amz-date:$t`n`nhost;x-amz-date`n$payloadHash"
$canonicalRequestHash = [System.BitConverter]::ToString((New-Object Security.Cryptography.SHA256Managed).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($canonicalRequest))).Replace("-", "").ToLower()
$credentialScope = "$date/$region/$service/aws4_request"
$stringToSign = "$algorithm`n$t`n$credentialScope`n$canonicalRequestHash"
# Sign key
function HMACSHA256($key, $data) { return (New-Object System.Security.Cryptography.HMACSHA256([System.Text.Encoding]::UTF8.GetBytes($key))).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($data)) }
$kDate = HMACSHA256 ("AWS4" + $awsSecretKey) $date
$kRegion = HMACSHA256 $kDate $region
$kService = HMACSHA256 $kRegion $service
$kSigning = HMACSHA256 $kService "aws4_request"
# Signature
$signatureBytes = HMACSHA256 $kSigning $stringToSign
$signature = [System.BitConverter]::ToString($signatureBytes).Replace("-", "").ToLower()
return "$algorithm Credential=$awsAccessKey/$credentialScope, SignedHeaders=host;x-amz-date, Signature=$signature", $t
}
# === 3️⃣ REQUEST AUF OFFER LISTINGS API ===
$uri = "/products/pricing/v0/offerListings?MarketplaceId=$marketplaceId&Asins=$asin"
$payload = "" # GET Request ohne Body
$authHeader, $amzDate = Get-AWSSignature -method "GET" -service "execute-api" -region $region -host $host -uri $uri -payload $payload
$headers = @{
"x-amz-access-token" = $lwaToken
"x-amz-date" = $amzDate
"Authorization" = $authHeader
"Content-Type" = "application/json"
}
$url = "https://$host$uri"
try {
$response = Invoke-RestMethod -Method Get -Uri $url -Headers $headers
if ($response.OfferListings.Count -gt 0) {
$lieferzeit = $response.OfferListings[0].Availability.Message
Write-Host "Lieferzeit für ASIN $asin: $lieferzeit"
} else {
Write-Host "Keine Lieferinformationen verfügbar."
}
} catch {
Write-Host "Fehler beim Abrufen der Daten: $_"
}