# Ext for getting voiceservercies.username and password

**URL:** https://forum.genieacs.com/t/ext-for-getting-voiceservercies-username-and-password/3079
**Category:** Uncategorized
**Created:** [October 16, 2022, 12:58pm UTC](https://forum.genieacs.com/t/ext-for-getting-voiceservercies-username-and-password/3079 "2022-10-16T12:58:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ideanethelp](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@ideanethelp](https://forum.genieacs.com/u/ideanethelp)
#### Post date: [October 16, 2022, 12:58pm UTC](https://forum.genieacs.com/t/ext-for-getting-voiceservercies-username-and-password/3079/1 "2022-10-16T12:58:24Z")

</div>

Hi folks,  
I want to read username and password of our voice services from an api for each device serial number.

i have written a script for now just returning a static username and password to see if it works.

script is /opt/genieacs/ext/test.js  
“use strict”;  
function GetSIP(args, callback) {  
let sipdata = “username: test”+“, password:1234”;  
callback(null, sipdata);  
}  
exports.GetSIP = GetSIP;

* * *

then in the provision the script is:-  
const res = ext(“ext-GetSIP”, “GetSIP”, “arg1”, “arg2”);  
log(res);

then i added this provision in the preset.

i can see in the logs that Script: username: test, password:1234 but i dont know how & where to set the other full parameter?  
i want to set the values of the following to paramters.

InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.1.SIP.AuthPassword   
InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.1.SIP.AuthUserName

Can someone guide me how to return the username,password and how to use those 2 variables. I assume i have to add the above 2 paramters in the inform ? but what variables will get me username and password? Please note username and password will be returned from my /opt/genieacs/ext/test.js  
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: [October 17, 2022, 4:19pm UTC](https://forum.genieacs.com/t/ext-for-getting-voiceservercies-username-and-password/3079/2 "2022-10-17T16:19:58Z")

</div>

If I’m understanding you correctly, you want to pass parameters into an extension script to pass along to an API? This is how I’ve accomplished that task:

```auto
// Provision script
const now = Date.now();
const serialNumber = declare('DeviceID.SerialNumber', {value: 1}).value[0];
const productClass = declare('DeviceID.ProductClass', {value: 1}).value[0];
const oui = declare('DeviceID.OUI', {value: 1}).value[0];
const deviceId = declare('DeviceID.ID', {value: 1}).value[0];
const params = {serial: serialNumber, productClass: productClass, oui: oui, deviceId: deviceId};

//Get the PPPoE creds
let config = ext('extensions', 'resetPppoe', JSON.stringify(params));

declare("InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.1.SIP.AuthUserName", {value: now}, {value: config.username});
declare("InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.1.SIP.AuthPassword", {value: now}, {value: config.password});

```

```auto
// Extension script
function resetPppoe(args, callback) {
    const params = JSON.parse(args[0]);

    const uri = `${API_URL}ResetPPPoECreds?serial=${params.serial}&productClass=${params.productClass}&oui=${params.oui}&deviceId=${encodeURIComponent(params.deviceId)}`;

    const options = buildHttpOptions(uri);

    const request = https.request(options, (response) => {
        if (response.statusCode === 404) {
            return callback(null, null);
        }

        if (response.statusCode >= 400) {
            const message = `Unexpected error resetting PPPoE credentials. Response Code: ${response.statusCode}. Status Message: ${response.statusMessage}. Response Type: ${typeof response.statusCode}`;
            return callback(new Error(message));
        }

        let data = '';
        response.on('data', d => data = data + d.toString());

        response.on('end', () => {
            let result = JSON.parse(data);

            // This data gets returned to the provision script in the config variable
            return callback(null, result);
        });
    });

    request.on('error', (err) => callback(err));

    request.end();
}

```

---

<div class="post-metadata">

### Author: ![ideanethelp](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@ideanethelp](https://forum.genieacs.com/u/ideanethelp)
#### Post date: [October 18, 2022, 12:55am UTC](https://forum.genieacs.com/t/ext-for-getting-voiceservercies-username-and-password/3079/3 "2022-10-18T00:55:56Z")

</div>

Thank you so much! i have figured it out.
