How to get access token in website

rahilsharma
This is the code :
<form method="post" id="basket-form" action="https://kite.trade/connect/basket">
<input type="hidden" name="api_key" value="4slvsk0ov1w0zgvk" />
<input type="hidden" id="basket" name="data" value="" />
</form>
<script>
console.log("i was called");
function send(){
var your_basket=[{
"tradingsymbol": "INFY",
"exchange": "NSE",
"transaction_type": "BUY",
"order_type": "MARKET",
"quantity": 10
}, {
"tradingsymbol": "NIFTY15DECFUT",
"exchange": "NFO",
"transaction_type": "SELL",
"order_type": "LIMIT",
"price": 7845,
"quantity": 1
}];
document.getElementById("basket").value =JSON.stringify(your_basket);
document.getElementById("basket-form").submit();
};
</script>

I am submitting the form when user clicks submit. I have given a redirect url and receive the token in the url but it redirects the page and it reloads , so how to get the token from the url.

Also when using Publisher js plugin how can i get the token as the page is opened as a popup.
  • Vivek
    @rahilsharma After user click on "Finish" from order basket it redirects to the redirect url with request token which you can detect it and exchange it for access token. You can edit redirect_url in developer console.
  • rahilsharma
    @vivek
    url with request token which you can detect it and exchange it for
    Can u plz tell how can i detect it?
  • Kailash
    Whatever app or script you are running at the redirect_url will receive the token as a GET query parameter.
  • rahilsharma
    So how will identify which users access token is this , as i get a redirect_url only which has get query parameter ? So this is what i am doing right now :
    I have a single page app , now i will embed the kite button in my page and after that user will click on it and will be taken to kite login page where he will enter his details and place trades . After completion of trade my redirect url will be called ..... now from here what do i need to do to get the token.
  • Vivek
    The redirect url should be the part of your app and when you get the redirect back you can check for the GET query param request_token and exchange it for access token. You get details like user id along with access token to identify the authenticated user.
Sign In or Register to comment.