'Search not working in restlet SuiteScript 2.0

I am trying to use search.create in RESTlet to check whether a contact exist in my netsuite account or not. This is my code

define(['N/record','N/search'],

function(record,search) {

function dosearch(contact_mail){
  var result;
  try{
    result = search.create({
                 type : record.Type.CONTACT,
                 filters:['email','IS',contact_mail],
                   columns: ['email']
             }).run().getRange({
                 start: 0,
                 end: 1
             });
    log.debug(result);
  } catch(e){
    result = e;
  }
  return result;
}
function doGet(requestParams) {
    
  var contact_mail = requestParams.email;
  log.debug(contact_mail);
  var result = dosearch(contact_mail);          
    return result;
}

And I am accesing this RESTlet from my system using this node js code.

async function myGet(){

var para = {id: 'my_id' , email: 'email'};
var accountSettings = {
    //'Content-Type': 'application/json',
    //params: para,
    accountId: account_id,
    tokenKey: token_key,
    tokenSecret: token_secret,
    consumerKey: consumer_key,
    consumerSecret: consumer_secret };
var urlSettings = {
    url: link
 }

var myInvoices = nsrestlet.createLink(accountSettings, urlSettings)


try{
    var res = await myInvoices.get(para);
    console.log(res);
} catch(e){
    console.log(e);
}   
}

Is there something wrong with the code? I tried same search code with user event script and it worked there but its not working in RESTlet. Can someone help me with this.



Solution 1:[1]

Silently failing a search is an indicator that the role you are using with your RESTlet doesn't have access to contacts. I generally see this with transactions I'd expect contacts work similarly because under the covers a contact is a form of entity.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bknights