Can someone help me convert this Curl request into node.js












0














curl 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json' 

X POST
data-urlencode 'To=+971566820680'
data-urlencode 'From=+971556309806'
data-urlencode 'Url=https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json'

data-urlencode 'ApplicationSid=APae94ada54ea05d0dabde55dc7a346178'
data-urlencode 'Method=POST'
-u AC7f9cc91207db898bb0ddee8e09d707b5:9b96d9f573a7bbcadce5fa88eced3b66


Above is the code I want to convert to NodeJS



Ideally, I want to have an Azure function (written in NodeJS)










share|improve this question




















  • 2




    Have you tried to write any NodeJS code yourself for the azure function?
    – technogeek1995
    Nov 20 at 18:56
















0














curl 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json' 

X POST
data-urlencode 'To=+971566820680'
data-urlencode 'From=+971556309806'
data-urlencode 'Url=https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json'

data-urlencode 'ApplicationSid=APae94ada54ea05d0dabde55dc7a346178'
data-urlencode 'Method=POST'
-u AC7f9cc91207db898bb0ddee8e09d707b5:9b96d9f573a7bbcadce5fa88eced3b66


Above is the code I want to convert to NodeJS



Ideally, I want to have an Azure function (written in NodeJS)










share|improve this question




















  • 2




    Have you tried to write any NodeJS code yourself for the azure function?
    – technogeek1995
    Nov 20 at 18:56














0












0








0







curl 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json' 

X POST
data-urlencode 'To=+971566820680'
data-urlencode 'From=+971556309806'
data-urlencode 'Url=https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json'

data-urlencode 'ApplicationSid=APae94ada54ea05d0dabde55dc7a346178'
data-urlencode 'Method=POST'
-u AC7f9cc91207db898bb0ddee8e09d707b5:9b96d9f573a7bbcadce5fa88eced3b66


Above is the code I want to convert to NodeJS



Ideally, I want to have an Azure function (written in NodeJS)










share|improve this question















curl 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json' 

X POST
data-urlencode 'To=+971566820680'
data-urlencode 'From=+971556309806'
data-urlencode 'Url=https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json'

data-urlencode 'ApplicationSid=APae94ada54ea05d0dabde55dc7a346178'
data-urlencode 'Method=POST'
-u AC7f9cc91207db898bb0ddee8e09d707b5:9b96d9f573a7bbcadce5fa88eced3b66


Above is the code I want to convert to NodeJS



Ideally, I want to have an Azure function (written in NodeJS)







node.js azure curl azure-functions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 18:57









Federico Grandi

2,59521126




2,59521126










asked Nov 20 at 17:55









Reina

81




81








  • 2




    Have you tried to write any NodeJS code yourself for the azure function?
    – technogeek1995
    Nov 20 at 18:56














  • 2




    Have you tried to write any NodeJS code yourself for the azure function?
    – technogeek1995
    Nov 20 at 18:56








2




2




Have you tried to write any NodeJS code yourself for the azure function?
– technogeek1995
Nov 20 at 18:56




Have you tried to write any NodeJS code yourself for the azure function?
– technogeek1995
Nov 20 at 18:56












1 Answer
1






active

oldest

votes


















1














If you check out this link - it allows you to convert any curl request into code for several languages. As a result, I was able to come up with this - I made a few changes. Note: you'll need to install request as an npm module:



const request = require('request');

const options = {
url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
method: 'POST',
auth: {
'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
}
};

function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}

request(options, callback);


To convert this code into something that an Azure Function can use, you'll need to set up the context objection that is used for the callback. This is for an Azure 2.0 Function. First, you need to import the npm module needed (and install it in the Kudu area of the Azure Function app). The function stub they give you will give you the module.exports function stub. What I have done below is filled in the code from your curl request and applied it to the Azure function. At the bottom, you'll see context.res. context.res represents the response that calling this Azure function via HTTP will yield. I have filled in the body with the response from the API request that you have asked for.



const rp = require('request-promise');
module.exports = async function (context, req) {

const options = {
url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
method: 'POST',
auth: {
'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
}
};

const response = await rp(options);

context.res = {
status: 200,
body: response
};
};





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398819%2fcan-someone-help-me-convert-this-curl-request-into-node-js%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    If you check out this link - it allows you to convert any curl request into code for several languages. As a result, I was able to come up with this - I made a few changes. Note: you'll need to install request as an npm module:



    const request = require('request');

    const options = {
    url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
    method: 'POST',
    auth: {
    'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
    'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
    }
    };

    function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
    console.log(body);
    }
    }

    request(options, callback);


    To convert this code into something that an Azure Function can use, you'll need to set up the context objection that is used for the callback. This is for an Azure 2.0 Function. First, you need to import the npm module needed (and install it in the Kudu area of the Azure Function app). The function stub they give you will give you the module.exports function stub. What I have done below is filled in the code from your curl request and applied it to the Azure function. At the bottom, you'll see context.res. context.res represents the response that calling this Azure function via HTTP will yield. I have filled in the body with the response from the API request that you have asked for.



    const rp = require('request-promise');
    module.exports = async function (context, req) {

    const options = {
    url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
    method: 'POST',
    auth: {
    'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
    'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
    }
    };

    const response = await rp(options);

    context.res = {
    status: 200,
    body: response
    };
    };





    share|improve this answer




























      1














      If you check out this link - it allows you to convert any curl request into code for several languages. As a result, I was able to come up with this - I made a few changes. Note: you'll need to install request as an npm module:



      const request = require('request');

      const options = {
      url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
      method: 'POST',
      auth: {
      'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
      'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
      }
      };

      function callback(error, response, body) {
      if (!error && response.statusCode == 200) {
      console.log(body);
      }
      }

      request(options, callback);


      To convert this code into something that an Azure Function can use, you'll need to set up the context objection that is used for the callback. This is for an Azure 2.0 Function. First, you need to import the npm module needed (and install it in the Kudu area of the Azure Function app). The function stub they give you will give you the module.exports function stub. What I have done below is filled in the code from your curl request and applied it to the Azure function. At the bottom, you'll see context.res. context.res represents the response that calling this Azure function via HTTP will yield. I have filled in the body with the response from the API request that you have asked for.



      const rp = require('request-promise');
      module.exports = async function (context, req) {

      const options = {
      url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
      method: 'POST',
      auth: {
      'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
      'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
      }
      };

      const response = await rp(options);

      context.res = {
      status: 200,
      body: response
      };
      };





      share|improve this answer


























        1












        1








        1






        If you check out this link - it allows you to convert any curl request into code for several languages. As a result, I was able to come up with this - I made a few changes. Note: you'll need to install request as an npm module:



        const request = require('request');

        const options = {
        url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
        method: 'POST',
        auth: {
        'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
        'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
        }
        };

        function callback(error, response, body) {
        if (!error && response.statusCode == 200) {
        console.log(body);
        }
        }

        request(options, callback);


        To convert this code into something that an Azure Function can use, you'll need to set up the context objection that is used for the callback. This is for an Azure 2.0 Function. First, you need to import the npm module needed (and install it in the Kudu area of the Azure Function app). The function stub they give you will give you the module.exports function stub. What I have done below is filled in the code from your curl request and applied it to the Azure function. At the bottom, you'll see context.res. context.res represents the response that calling this Azure function via HTTP will yield. I have filled in the body with the response from the API request that you have asked for.



        const rp = require('request-promise');
        module.exports = async function (context, req) {

        const options = {
        url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
        method: 'POST',
        auth: {
        'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
        'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
        }
        };

        const response = await rp(options);

        context.res = {
        status: 200,
        body: response
        };
        };





        share|improve this answer














        If you check out this link - it allows you to convert any curl request into code for several languages. As a result, I was able to come up with this - I made a few changes. Note: you'll need to install request as an npm module:



        const request = require('request');

        const options = {
        url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
        method: 'POST',
        auth: {
        'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
        'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
        }
        };

        function callback(error, response, body) {
        if (!error && response.statusCode == 200) {
        console.log(body);
        }
        }

        request(options, callback);


        To convert this code into something that an Azure Function can use, you'll need to set up the context objection that is used for the callback. This is for an Azure 2.0 Function. First, you need to import the npm module needed (and install it in the Kudu area of the Azure Function app). The function stub they give you will give you the module.exports function stub. What I have done below is filled in the code from your curl request and applied it to the Azure function. At the bottom, you'll see context.res. context.res represents the response that calling this Azure function via HTTP will yield. I have filled in the body with the response from the API request that you have asked for.



        const rp = require('request-promise');
        module.exports = async function (context, req) {

        const options = {
        url: 'https://api.twilio.com/2010-04-01/Accounts/AC7f9cc91207db898bb0ddee8e09d707b5/Calls.json',
        method: 'POST',
        auth: {
        'user': 'AC7f9cc91207db898bb0ddee8e09d707b5',
        'pass': '9b96d9f573a7bbcadce5fa88eced3b66'
        }
        };

        const response = await rp(options);

        context.res = {
        status: 200,
        body: response
        };
        };






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 27 at 3:13









        Pang

        6,8601563101




        6,8601563101










        answered Nov 20 at 19:13









        technogeek1995

        3021318




        3021318






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398819%2fcan-someone-help-me-convert-this-curl-request-into-node-js%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen