# Extensions get, post, put?

**URL:** <https://forum.genieacs.com/t/extensions-get-post-put/493>\
**Category:** Uncategorized\
**Created:** [December 3, 2019, 6:51am UTC](https://forum.genieacs.com/t/extensions-get-post-put/493 "2019-12-03T06:51:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![metroport\_tp](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@metroport\_tp](https://forum.genieacs.com/u/metroport_tp)\
**Post date:** [December 3, 2019, 6:51am UTC](https://forum.genieacs.com/t/extensions-get-post-put/493/1 "2019-12-03T06:51:16Z")

</div>

Which http methods can I use in GenieACS extensions?  
If I use the POST method, I get a timeout in GenieACS log, despite the fact that extension executes and ends in milliseconds when I test it manually in linux cli.  
Does someone have a working example of an extension with the POST method?  
Thanks in advance!

---

<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:** [December 3, 2019, 5:33pm UTC](https://forum.genieacs.com/t/extensions-get-post-put/493/2 "2019-12-03T17:33:08Z")

</div>

You are probably getting the timeout in the log because you are not calling the callback in the extension. Take this stripped down extension. I’ve put a few comments in here where the callback is invoked. This callback is what gets the data back to the provision or vparam script.

```javascript
const process = require('process');
const API_URL = process.env.DASHBOARD_API_URL || 'https://my.domain.com/api/ACS/';

const url = require('url');
const http = require(API_URL.split(':', 1)[0]);

function getConfig(args, callback) {
    let params = JSON.parse(args[0]);

    const uri = API_URL + 'Foo?serial=' + params.serial + '&productClass=' + params.productClass + '&oui=' + params.oui + '&deviceId=' + encodeURIComponent(params.deviceId);

    let options = url.parse(uri);
    options.headers = {accept: 'application/json', 'content-type': 'application/json'};

    let request = http.post(options, function (response) {
        if (response.statusCode >= 400) {
            return callback(new Error('Unexpected error posting data. Response Code: ' + response.statusCode + '. Status Message: ' + response.statusMessage));
        }

        let data = '';
        response.on('data', function (d) {
            data = data + d.toString();
        });

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

            // Invoke the callback so our results get back to the calling provision script
            return callback(null, result);
        });
    });

    request.on('error', function (err) {
        // Let the calling script know there was an error
        callback(err);
    });
}

exports.getConfig = getConfig;

```

---

<div class="post-metadata">

**Author:** ![metroport\_tp](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@metroport\_tp](https://forum.genieacs.com/u/metroport_tp)\
**Post date:** [December 3, 2019, 6:07pm UTC](https://forum.genieacs.com/t/extensions-get-post-put/493/3 "2019-12-03T18:07:08Z")

</div>

Dan,

Thank you for your answer. But I didn’t ask about the GET method, which works fine for me. I asked about the POST method. My script used in extension called from GenieACS returns timeout if I use POST or PUT.  
The same script called manually with a node in a Linux bash environment returns callback and ends in a few milliseconds. I didn’t analyse GenieACS code so I prefer ask if it is possible to use in extensions other http methods than GET. My current case is PUT cause I want explitly “inform” my CRM that provisioning just finished. May be that I didn’t clarify it before, sorry 😉

---

<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:** [December 3, 2019, 6:12pm UTC](https://forum.genieacs.com/t/extensions-get-post-put/493/4 "2019-12-03T18:12:49Z")

</div>

Sorry, this was the shorter of the methods in an extension script I have, one of which posts. But request.post should work fine in the above example, as long as you call the callback when you are done.

Here is a post example:

```javascript
function diagnostic(args, callback) {
    let params = JSON.parse(args[0]);

    const uri = API_URL + "Diagnostic?serial=" + params.serial + '&productClass=' + params.productClass + '&oui=' + params.oui;
    const logParams = { deviceId: params.deviceId };
    logger.info(Object.assign({ message: uri }, logParams, params));

    request({
        uri: uri,
        method: 'POST',
        json: true,
        body: params
    }, function (error, response) {
        if (!error && response.statusCode === 200) {
            callback(null, {});
        } else {
            logger.error(Object.assign({ message: 'Unexpected error sending event', statusCode: response.statusCode, statusMessage: response.statusMessage }, logParams));
            callback(error);
        }
    });
}

```
