skip to Main Content

In my application i need to use twillio module API to send and receive sms.But i dont know how to call other API methods in node.js.Now im using node.js with socketstream.

2

Answers


  1. You can use the request module, the documentation has a lot of great examples how to call REST API methods.

    And for Twilio you can read this guide “Getting Started with Twilio and Node.js” and use the twilio module.

    Login or Signup to reply.
  2. Let’s assume you have an API call that is already working with curl, something like:

    curl -X POST -H “Token:SecurityToken”
    -H “Content-Type: application/json”
    https://yourURL.com
    -d ‘{“records”:[{“value”:”Testing the API Function”}]}’

    You will need to first install proper modules for your node.js:

    npm install request
    

    Then you will need to create a js file with the following content:

    var Request = require("request");
    
    // Preparing API CAll with Post Action and its arguments
    Request.post({
        "headers": { "content-type": "application/json" ,"Token":"SecurityToken" },
        "url": "YourURL.com",
        "body": JSON.stringify({"records":[{"value":"Testing the API Function"}]})
    }, (error, response, body) => {
        if(error) {
            return console.dir(error);
        }
        // console.log(response);
        console.dir(JSON.parse(body));
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search