# "Sumarize" API query

**URL:** <https://forum.genieacs.com/t/sumarize-api-query/1970>\
**Category:** Uncategorized\
**Created:** [August 26, 2021, 2:02am UTC](https://forum.genieacs.com/t/sumarize-api-query/1970 "2021-08-26T02:02:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alvarocduquia](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@alvarocduquia](https://forum.genieacs.com/u/alvarocduquia)\
**Post date:** [August 26, 2021, 2:02am UTC](https://forum.genieacs.com/t/sumarize-api-query/1970/1 "2021-08-26T02:02:13Z")

</div>

Hi guys!

It is possible to “sumarize” device search query by **ExternalIPAddress** parameter from API?

Almost devices uses **InternetGatewayDevice.WANDevice.1.WANConnectionDevice.X.WANIPConnection.1.ExternalIPAddress** to show their IP external address, but some devices uses **InternetGatewayDevice.WANDevice.2.WANConnectionDevice.X.WANIPConnection.1.ExternalIPAddress**.

I have tried **{“InternetGatewayDevice.WANDevice.\*.WANConnectionDevice.\*.WANPPPConnection.\*.ExternalIPAddress”: “1.2.3.4”}** query but it doesn’t works.

Thanks!

---

<div class="post-metadata">

**Author:** ![akcoder](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/akcoder/32/11_2.png) [@akcoder](https://forum.genieacs.com/u/akcoder)\
**Post date:** [August 26, 2021, 2:59am UTC](https://forum.genieacs.com/t/sumarize-api-query/1970/2 "2021-08-26T02:59:55Z")

</div>

Your best bet is a [virtual parameter](https://docs.genieacs.com/en/latest/virtual-parameters.html).

```auto
let keys = [
    'Device.PPP.Interface.*.IPCP.LocalIPAddress',
    'InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANIPConnection.*.ExternalIPAddress'
];

let result = getParameterValue(keys);

return {writable: false, value: [result, "xsd:string"]};

function getParameterValue(keys) {
    for (let key of keys) {
        let d = declare(key, {path: Date.now() - (120 * 1000), value: Date.now()});

        for (let item of d) {
            if (item.value && item.value[0]) {
                return item.value[0];
            }
        }
    }

    return '';
}

```

---

<div class="post-metadata">

**Author:** ![alvarocduquia](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@alvarocduquia](https://forum.genieacs.com/u/alvarocduquia)\
**Post date:** [August 26, 2021, 2:45pm UTC](https://forum.genieacs.com/t/sumarize-api-query/1970/3 "2021-08-26T14:45:28Z")

</div>

Your tip worked perfectly for my purpose!

Thanks @akcoder!

---

<div class="post-metadata">

**Author:** ![akcoder](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/akcoder/32/11_2.png) [@akcoder](https://forum.genieacs.com/u/akcoder)\
**Post date:** [August 26, 2021, 4:32pm UTC](https://forum.genieacs.com/t/sumarize-api-query/1970/4 "2021-08-26T16:32:16Z")

</div>

You are welcome. VParams do not auto-refresh. And sadly, there is no event code a CPE is required to send when it connects to the interwebs. So you will need to periodically refresh the value. I would create two presets. One that has `0 BOOT` as the event and refreshes the vparam. And another more general purpose preset which periodically refreshes values you need.

Here is a script I wrote which refreshes DSL stats. You are welcome to take the script in whole or in part. This script refreshes DSL info every 18 hours, and interface stats every 6 hours.

```auto
let oneDay = 24 * (60 * 60) * 1000;
let dslRefreshInterval = Date.now() - (oneDay * 1.5);
let statsRefreshInterval = Date.now() - (oneDay * 0.25);

let paramNames = [
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.ModulationType",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamCurrRate",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamCurrRate",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamMaxRate",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamMaxRate",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamNoiseMargin",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamNoiseMargin",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamAttenuation",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamAttenuation",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.UpstreamPower",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.DownstreamPower",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.LinkEncapsulationUsed",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.LineNumber",
    "InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.X_BROADCOM_COM_BondingLineNumber",
    "Device.DSL.Channel.*.UpstreamCurrRate",
    "Device.DSL.Channel.*.DownstreamCurrRate",
    "Device.DSL.Channel.*.UpstreamMaxBitRate",
    "Device.DSL.Channel.*.DownstreamMaxBitRate",
    "Device.DSL.Channel.*.LinkEncapsulationUsed",
    "Device.DSL.Line.*.UpstreamNoiseMargin",
    "Device.DSL.Line.*.DownstreamNoiseMargin",
    "Device.DSL.Line.*.UpstreamAttenuation",
    "Device.DSL.Line.*.DownstreamAttenuation",
    "Device.DSL.Line.*.UpstreamPower",
    "Device.DSL.Line.*.DownstreamPower",
    "Device.DSL.Line.*.LineNumber",
    "Device.DSL.Line.*.X_ZYXEL_BondingLineNumber",
    "Device.DSL.ChannelNumberOfEntries",
    "Device.DSL.LineNumberOfEntries",
];

for(let key of paramNames) {
    declare(key, {path: oneDay * 2, value: dslRefreshInterval});
}

declare("InternetGatewayDevice.WANDevice.*.WANDSLInterfaceConfig.Stats.*.*", {path: oneDay * 2, value: statsRefreshInterval});
declare("Device.DSL.Line.*.Stats.*.*", {path: oneDay * 2, value: statsRefreshInterval});
declare("Device.DSL.Channel.*.Stats.*.*", {path: oneDay * 2, value: statsRefreshInterval});

```
