Skip to content

getFavorites() returns fewer entries due to wrong User-Agent #540

@jordansissel

Description

@jordansissel

When calling getFavorites(), in my test, node-sonos gives me two (2) results. In the macOS Sonos app, I show four (4) entries.

Expected Behavior

It should return the same items as the Sonos app has.

Current Behavior

It omits (due to some weirdness in Sonos UPnP?) certain records.

Possible Solution

const axios = require("axios");
axios.defaults.headers.common['User-Agent'] = "Linux UPnP/1.0 Sonos/70.4-35282 (MDCR_Mac14,2)"

This sets the default 'User-Agent' header on all axios requests.

I discovered this by sniffing traffic between the Sonos app and my network and comparing the results, then trying to change one thing at a time to see what improved the outcome.

Sample code or executed example

      device.getFavorites()
        .then(result => { console.log(`Total (default): ${result.total}`) })
        .then(() => {
            const axios = require("axios");
            axios.defaults.headers.common['User-Agent'] = "Linux UPnP/1.0 Sonos/70.4-35282 (MDCR_Mac14,2)"
            return device.getFavorites()
        }).then(result => { console.log(`Total (after setting user-agent): ${result.total}`) })
Total (default): 2
Total (after setting user-agent): 4

Versions (and Environment)

Node version: v19.2.0
node-sonos version: 1.14.1
OS: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions