Getting Invalid TOTP/Token error in generateSession method call


  • Here are my code:

    require("dotenv").config();
    let { SmartAPI } = require("../lib");

    const API_KEY = process.env.API_KEY;
    const CLIENT_CODE = process.env.CLIENT_ID;
    const PASSWORD = process.env.PASSWORD;
    const TOTP = process.env.TOTP;

    let smart_api = new SmartAPI({
    api_key: API_KEY,
    });

    smart_api
    .generateSession(CLIENT_CODE, PASSWORD, TOTP)
    .then((data) => {
    console.log(data);
    return smart_api.getProfile();
    })
    .then((data) => {
    console.log(JSON.stringify(data, null, 2));
    })
    .catch((error) => {
    console.log(error);
    });

    Getting following response:
    {
    status: false,
    message: 'Invalid totp',
    errorcode: 'AB1050',
    data: null
    }
    {
    "success": false,
    "message": "Invalid Token",
    "errorCode": "AG8001",
    "data": ""
    }

    @admin Could you please help?


  • @brajalal

    TOTP expires within a minute.
    Storing a TOTP in env variable will not work

    Regards,
    SmartAPI Team