Basic Usage
2 Searching

Searching

  • Normal search for a phone number.
import truecallerjs, { SearchData, Format } from "truecallerjs";
 
async function performTruecallerSearch(): Promise<void> {
  const searchData: SearchData = {
    number: "9912345678",
    countryCode: "IN",
    installationId: "a1k07--Vgdfyvv_rftf5uuudhuhnkljyvvtfftjuhbuijbhug",
  };
 
  try {
    const response: Format = await truecallerjs.search(searchData);
    console.log(response.json());
 
    // Additional response methods:
    // console.log(response.xml());
    // console.log(response.yaml());
    // console.log(response.text());
 
    // Example of available data from the response:
    console.log(response.getName()); // "Sumith Emmadi"
    console.log(response.getAlternateName()); // "sumith"
    console.log(response.getAddresses()); // {....}
    console.log(response.getEmailId()); // example@domain.com
    console.log(response.getCountryDetails()); // {...}
  } catch (error) {
    console.error("Error occurred:", error);
  }
}
 
performTruecallerSearch();
  • number : Phone number
  • countryCode : Country code to use by default If any phone number is not in e164 format(Internation format). Eg: Country code for India is "IN".
  • installationId : InstallationId Here, you need to login first to use it. Use the truecallerjs login command to login to your account.

In the above example, the truecallerjs package is used to search for a phone number. The search_data object contains the necessary parameters, including the number, country code, and installation ID. The response from the truecallerjs.search() function provides various methods to access the returned data.

Note : Make sure to log in using the truecallerjs login command and obtain your installation ID using the truecallerjs -i command.

response Object

The response object represents the response obtained from a query. It provides various methods and properties to access and manipulate the response data.

Methods

  • response.json(color)

    • Parameters:
      • color (Boolean): Indicates whether to add color formatting to the JSON output.
    • Returns: JSON response as a string.
    • Description: This method returns the JSON response as a string. The optional color parameter determines whether to include color formatting in the output.
  • response.xml(color)

    • Parameters:
      • color (Boolean): Indicates whether to add color formatting to the XML output.
    • Returns: XML output as a string.
    • Description: This method returns the XML output as a string. The optional color parameter determines whether to include color formatting in the output.
  • response.yaml(color)

    • Parameters:
      • color (Boolean): Indicates whether to add color formatting to the YAML output.
    • Returns: YAML output as a string.
    • Description: This method returns the YAML output as a string. The optional color parameter determines whether to include color formatting in the output.
  • response.text(color, space)

    • Parameters:
      • color (Boolean): Indicates whether to add color formatting to the JSON output.
      • space (Boolean): Indicates whether to include spacing between keys and values in the JSON output.
    • Returns: JSON response as a string.
    • Description: This method returns the JSON response as a string. The optional color parameter determines whether to include color formatting in the output, and the space parameter determines whether to include spacing between keys and values.

Properties

  • response.getName()

    • Returns: The name associated with the response.
    • Description: This method retrieves the name associated with the response.
  • response.getAlternateName()

    • Returns: The alternate name associated with the response.
    • Description: This method retrieves the alternate name associated with the response.
  • response.getAddresses()

    • Returns: The addresses associated with the response.
    • Description: This method retrieves the addresses associated with the response. The details of the addresses can be accessed using the returned object.
  • response.getEmailId()

    • Returns: The email ID associated with the response.
    • Description: This method retrieves the email ID associated with the response.
  • response.getCountryDetails()

    • Returns: The country details associated with the response.
    • Description: This method retrieves the country details associated with the response. The details can be accessed using the returned object.