0

I am able to call site24x7api to fetch all the customers details (E.g user_id, name, zaaid) in terminal with the help of .js file

INPUT :

var request = require('request');

var headers = {
    'Content-Type': 'application/json;charset=UTF-8',
    'Accept': 'application/json; version=2.0',
    'Authorization': 'Zoho-authtoken xxx12sdc231xx'
};

var options = {
    url: 'https://www.site24x7.com/api/short/msp/customers',
    headers: headers
};

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

request(options, callback);

OUTPUT(In terminal) :

{
"user_id":"12345678912123",
"name":"abc",
"zaaid":"12341234"
},
{
"user_id":"98123141231233",
"name":"Xyz",
"zaaid":"43241123"
} ... and many more

Now suppose, BOT asks user for name and user enter name as

abc

The program should match the name which user enters (stored in '${session.dialogData.Companyname}' ) and the name present in the terminal and BOT should return the zaaid(int) or user_id(int) related to that particular user that is 12341234 in this case to the BOT interface

I've tried

Link 1

Link 2

Link 3

SMshrimant
  • 638
  • 9
  • 15

1 Answers1

0

Use Array to loop through your json file, For Example:

var users = [{
"user_id":"12345678912123",
"name":"abc",
"zaaid":"12341234"
},
{
"user_id":"98123141231233",
"name":"Xyz",
"zaaid":"43241123"
}]

for (i=0; i<users.length; i++) {
  if (users[i].name = "the_name") {
    do_something....
  }
}
DJ MixRhymez
  • 40
  • 1
  • 9