Search Station based on the last operator used

Just for the record, I can use Station API like this to search for the Stations with the user ID uD7hMd2Hpr2KiD6ZK (blue) using it.
I can put the id of the station to the last part of the URL to open that Station. (green)

async function getJson(url,username,password){
    try {
        const response=await fetch(url,{headers:{Authorization: "Basic " + btoa(`${username}:${password}`)}});
    if(!response.ok){
      throw new Error(`Response status: ${response.status}`);
    }
    return await response.json();
    } catch (error) {
        console.error(error.message);
    }
}
const username='PUT_YOUR_API_KEY_HERE';
const password='PUT_YOUR_SECRET_HERE';
const url ='https://PUT_YOUR_TULIP_SERVER_HERE/api/stations/v1/w/DEFAULT/stations'
async function getAllStations(url,username,password){
    json=await getJson(url,username,password);
    items=json.items;
    while(np=json.nextPage){
        json=await getJson(np,username,password);
        items.push(... json.items); 
    }
    if(json.count != items.length){
        throw new Error(`Wrong count : ${json.count} , ${items.length}`);
    }
    return items;
}
stations=await getAllStations(url,username,password);
console.table(stations.filter(e=>e.operatorId=='uD7hMd2Hpr2KiD6ZK'));
1 Like