Skip to content

Nodejs

Getting started with Nodejs

To use the API with Nodejs use the following example

Using Axios

    var axios = require('axios');
    var data = JSON.stringify({
    "api_key": "777XXXXXXXXXXXXXXXXXXXAWVwNpSM=",
    "pc": "HOME006"
    });

    var config = {
    method: 'post',
    url: 'https://apiv1.pataa.com/get-pataa',
    headers: { 
        'Content-Type': 'application/json'
    },
    data : data
    };

    axios(config)
    .then(function (response) {
    console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
    console.log(error);
    });

Using Native Nodejs

    var https = require('follow-redirects').https;
    var fs = require('fs');

    var options = {
    'method': 'POST',
    'hostname': 'pataa.in',
    'port': 5056,
    'path': '/prt-pc-dtl',
    'headers': {
        'Content-Type': 'application/json'
    },
    'maxRedirects': 20
    };

    var req = https.request(options, function (res) {
    var chunks = [];

    res.on("data", function (chunk) {
        chunks.push(chunk);
    });

    res.on("end", function (chunk) {
        var body = Buffer.concat(chunks);
        console.log(body.toString());
    });

    res.on("error", function (error) {
        console.error(error);
    });
    });

    var postData = JSON.stringify({
    "api_key": "777XXXXXXXXXXXXXXXXXXXAWVwNpSM=",
    "pc": "HOME006"
    });

    req.write(postData);

    req.end();

Using Nodejs Request

    var request = require('request');
    var options = {
    'method': 'POST',
    'url': 'https://apiv1.pataa.com/get-pataa',
    'headers': {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        "api_key": "777XXXXXXXXXXXXXXXXXXXAWVwNpSM=",
        "pc": "HOME006"
    })

    };
    request(options, function (error, response) {
    if (error) throw new Error(error);
    console.log(response.body);
    });