Fetch Json Data Set Using Parameter

I want to fetch JSON data set using UrlFetchApp but unfortunately am not able to do so. The reference code and data are attached, any help is highly appreciated.

CODE

function doGet(e) {
  var sheetId = "sheetid";
  var primaryEmail = e.parameter.primaryEmail;
  var softwareId = e.parameter.softwareId;
  var licensedScriptIds = e.parameter.licensedScriptIds;

  if (!primaryEmail || !softwareId || !licensedScriptIds) {
    return ContentService.createTextOutput("ERROR: primaryEmail, softwareId, and licensedScriptIds parameters are required.");
  }

  var sheet = SpreadsheetApp.openById(sheetId).getSheets()[0];
  var data = sheet.getDataRange().getValues();
  var headers = data.shift();
  var primaryEmailIndex = headers.indexOf("primaryEmail");
  var softwareIdIndex = headers.indexOf("softwareId");
  var licensedScriptIdsIndex = headers.indexOf("licensedScriptIds");
  var jsonData = [];

  for (var i = 0; i < data.length; i++) {
    if (data[i][primaryEmailIndex] == primaryEmail && data[i][softwareIdIndex] == softwareId && data[i][licensedScriptIdsIndex] == licensedScriptIds) {
        jsonData.push(data[i]);
    }
  }
  if(jsonData.length === 0) {
    return ContentService.createTextOutput("No match found");
  } else {
    return ContentService.createTextOutput(JSON.stringify(jsonData));
  }
};

JSON DATA

[{"Primary Email Address":"abc@gmail.com","Software ID":"TBBINV0719SS","Software Version":"Enterprise","License Status":"Expired","Start Date":"2019-07-26T18:30:00.000Z","Expiry Date":"2022-12-30T18:30:00.000Z","License Type":"User","License(s)":1,"Licensed User(s)":"abc@gmail.com","Domain":"","License Key":"","Software Status":"","Licensed Script ID(s)":""},{"Primary Email Address":"ca@gmail.com","Software ID":"TBBINV0719SS","Software Version":"Enterprise","License Status":"Expired","Start Date":"2019-07-26T18:30:00.000Z","Expiry Date":"2022-12-30T18:30:00.000Z","License Type":"User","License(s)":1,"Licensed User(s)":"ca@gmail.com","Domain":"","License Key":"","Software Status":"","Licensed Script ID(s)":""}


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation