Invalid page is been rendered

I am following the Get Token and Authorize page to access response of
{
“email”: “",
“exchanges”: [“NSE”, “NFO”, “BSE”, “CDS”, “BFO”, “BCD”],
“products”: [“D”, “CO”, “I”],
“broker”: “UPSTOX”,
“user_id”: "
”,
“user_name”: “",
“order_types”: [“MARKET”, “LIMIT”, “SL”, “SL-M”],
“user_type”: “individual”,
“poa”: false,
“is_active”: true,
“access_token”: "
"
“extended_token”: "
******”
}
after i login with mobile number , passcode.
the response is not shown to me and app.get(“/”) is been opened .
here the code of backend and frontend






@vinod_mokashi,

As outlined in our documentation, which you can find at Upstox API Documentation - Authentication, there is a three-step process to generate your access_token:

  1. Start with OAuth Authentication, as described here: Perform Authentication.
  2. Follow this by receiving the Auth Code, detailed at: Receive Auth Code.
  3. Finally, use the Auth Code to generate your access_token, as explained here: Generate Access Token.

This process has been rigorously tested and successfully used by thousands of users, ensuring its reliability and effectiveness. I encourage you to carefully follow the instructions provided in these documentation links to generate your access_token.

If you continue to experience difficulties, please provide the CURL object of the request you’re making for further assistance.

Thank you!

const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const cors = require("cors");
const axios = require("axios");
const User = require("./models/User");
const app = express();
const PORT = 3001;
app.use(cors({ origin: "*" }));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

const UPSTOX_CLIENT_ID = "";
const UPSTOX_CLIENT_SECRET = "";
const UPSTOX_REDIRECT_URI = "http://127.0.0.1:3001";
const UPSTOX_API_VERSION = "2.0";
app.get("/", (req, res) => {
  res.send("Working");
});

app.get("/upstox-login", (req, res) => {
  const authorizeUrl = "https://api.upstox.com/v2/login/authorization/dialog";
  const queryParams = {
    client_id: UPSTOX_CLIENT_ID,
    redirect_uri: UPSTOX_REDIRECT_URI,
    apiVersion: UPSTOX_API_VERSION,
  };
  const upstoxLoginUrl = `${authorizeUrl}?${new URLSearchParams(queryParams)}`;
  res.json({ loginUrl: upstoxLoginUrl });
});

app.post("/upstox-callback", async (req, res) => {
  const code = req.body.code;
  if (!code) {
    return res.status(400).json({ error: "Authorization code not provided." });
  }
  const tokenUrl = "https://api.upstox.com/v2/login/authorization/token";
  const tokenParams = {
    code: code,
    client_id: "",
    client_secret: "
![Screenshot 2024-01-02 at 3.37.36 PM|690x368](upload://30yZ7Y9b6FzZCNE641cSEWN3jl9.png)
![Screenshot 2024-01-02 at 3.37.26 PM|690x368](upload://ky10rrUjbMgVUzfHRjy7jvNCNl6.png)
",
    redirect_uri: "http://localhost:3001/",
    grant_type: "authorization_code",
  };

  try {
    const tokenResponse = await axios.post(tokenUrl, tokenParams);

    res.json(tokenResponse.data);
  } catch (error) {
    console.error("Error exchanging code for token:", error.message);
    res.status(500).json({ error: "Internal Server Error" });
  }[quote="vinod_mokashi, post:1, topic:3605, full:true"]
I am following the Get Token and Authorize page to access response of 
{
  "email": "******",
  "exchanges": ["NSE", "NFO", "BSE", "CDS", "BFO", "BCD"],
  "products": ["D", "CO", "I"],
  "broker": "UPSTOX",
  "user_id": "******",
  "user_name": "******",
  "order_types": ["MARKET", "LIMIT", "SL", "SL-M"],
  "user_type": "individual",
  "poa": false,
  "is_active": true,
  "access_token": "******************"
  "extended_token": "******************"
}
after i login with mobile number , passcode.
the response is not shown to me and app.get("/") is been opened .
here the code of backend and frontend
[/quote]


});

here is after i enter pass code.
ss-
my redirect_uri & backend server path are same.


@vinod_mokashi,

As outlined in the Documentation, following successful authentication, the app will redirect to your specified redirect URL and provide an authorization code.

Once you receive this code at the redirect URL, you should then initiate a call to the /token API to obtain the access_token.

Thank you!

i am following and doing same task as mentioned in dcoument but i am unable to get access token
if u see code it will be clarified.
let me know that is redirect uri & backend url path should be same ?
i kept both at http://127.0.0.1:3001?code=Q6O9kV

@vinod_mokashi,

To generate the access_token, you need to make a request to the /token API using the auth code that you have received. Your approach so far is on the right track.

Next, you should proceed by making a call to the Token API, which will provide you with the access_token in response.

Please go ahead and make the call to the /token API. If you encounter any issues, don’t hesitate to let us know.

Thank you!

after following all steps still not able to generate access token.
i am trying since 2 hours

@Pradeep_Jaiswar issue is still pending

Please refer to the cURL shared in this post.