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 numbercountryCode
: 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 thetruecallerjs -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.
- Parameters:
-
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.
- Parameters:
-
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.
- Parameters:
-
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 thespace
parameter determines whether to include spacing between keys and values.
- Parameters:
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.