Get All Listing’s Additional Fees in Guesty (via API)

Recently had a need to get all the additional fees for each listing in Guesty (guesty.com) via the Guesty Open API. I did this with powershell:

PowerShell
$headers=@{}
$headers.Add("accept", "application/json")
# Authorisation header
$headers.Add("authorization", "Bearer your-token-goes-here")
# Get all the listings
# if you have more than one listing, you'll have to run this script, then increase the "skip" parameter below to 100, then run it again.
# and again if you have more than 200. And so on.
$response = Invoke-WebRequest -Uri 'https://open-api.guesty.com/v1/listings?limit=100&skip=0&active=true&fields=_id%20title%20nickname%20bedrooms' -Method GET -Headers $headers
$response = $response.Content
$results = ($response | ConvertFrom-Json).results

# go through each listing, and get it's additional fees.
$results | ForEach-Object{
    $uri = "https://open-api.guesty.com/v1/additional-fees/listing/" + $_._id
    # avoiding rate limits.
    Start-Sleep -Seconds 0.6
    
    $additionalFees = Invoke-WebRequest -Uri $uri -Method GET -Headers $headers
    $additionalFees = $additionalFees.Content
    $additionalFees = ($additionalFees | ConvertFrom-Json)

# and print out the results
    foreach ($additionalFees in $additionalFees) {
    Write-Host $_.nickname -NoNewline
    # \ is a character that we don't use ever in our listing nicknames, so was
    # a safe bet for the delimiter
    Write-Host "\" -NoNewline
    Write-Host  $additionalFees.name -NoNewline
    Write-Host "\" -NoNewline
    Write-Host $additionalFees.value

    }
}

Just need to fill in your token from the guesty authorisation endpoint, and away you go!

Leave a Reply

Your email address will not be published. Required fields are marked *