const axios = require('axios'); class TrueCaller { constructor({ phone, countryCode }) { if (isNaN(phone)) throw new Error('Invalid number input'); if (!countryCode) throw new Error('Country code is required'); this.phone = parseInt(phone); this.countryCode = countryCode; this.sessionId = null; this.token = null; } login = async function () { try { const { data } = await axios.post('https://asia-south1-truecaller-web.cloudfunctions.net/webapi/noneu/auth/truecaller/v1/send-otp', { phone: this.phone, countryCode: this.countryCode }, { headers: { accept: '*/*', 'content-type': 'application/json', origin: 'https://www.truecaller.com', referer: 'https://www.truecaller.com/', 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36' } }); this.sessionId = data.sessionId; return data.sessionId; } catch (error) { throw new Error(error.message); } } sendOtp = async function (otp) { try { if (!otp) throw new Error('Otp is required'); if (!this.sessionId) throw new Error('Please login first'); const { data } = await axios.post('https://asia-south1-truecaller-web.cloudfunctions.net/webapi/noneu/auth/truecaller/v1/verify-otp', { sessionId: this.sessionId, verificationCode: otp, phone: this.phone, countryCode: this.countryCode }, { headers: { accept: '*/*', 'content-type': 'application/json', origin: 'https://www.truecaller.com', referer: 'https://www.truecaller.com/', 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36' } }); this.token = data.accessToken; return data.accessToken; } catch (error) { throw new Error(error.message); } } checkNumber = async function (phone, countryCode = 'id') { try { if (!this.token) throw new Error('Login first'); if (isNaN(phone)) throw new Error('Phone number is required'); const { data } = await axios.get('https://asia-south1-truecaller-web.cloudfunctions.net/webapi/noneu/search/v2', { headers: { accept: '*/*', authorization: `Bearer ${this.token}`, 'content-type': 'application/json', origin: 'https://www.truecaller.com', referer: 'https://www.truecaller.com/', 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36' }, params: { q: phone, countryCode: countryCode, type: '44' } }); return data; } catch (error) { throw new Error(error.message); } } } // Usage: const t = new TrueCaller({ phone: '62xxx', countryCode: 'id' }); const resp = await t.login(); console.log(resp);