offsite order error

raaghulr
raaghulr edited January 2019 in Kite Publisher
<!DOCTYPE html>
<html>
<body>



<p id="demo"></p>


<script>
console.log("i was called");
function send(){
var your_basket=[{
"tradingsymbol": "INFY",
"exchange": "NSE",
"transaction_type": "BUY",
"order_type": "MARKET",
"quantity": 10
}];
document.getElementById("basket").value =JSON.stringify(your_basket);
document.getElementById("basket-form").submit();
};
</script>
<form method="post" id="basket-form" action="https://kite.trade/connect/basket">
<input type="hidden" name="api_key" value="4slvxxxxxxw0zgvk" />
<input type="hidden" id="basket" name="data" value="" />
<input type="submit" value="Submit"> //button-submit
</form>

</body>
</html>
output :
{"status":"error","message":"Invalid orders payload.","data":null,"error_type":"InputException"}

whats the error here, please help
  • rakeshr
    @raaghulr
    The problem is when the code is being executed. You are calling the element code gets before the DOM is finished loading. So, you can fix this by moving your JS code after the form initialization i.e at the end of the code.
  • raaghulr
    raaghulr edited January 2019
    <!DOCTYPE html>
    <html>
    <body>
    <p id="demo"></p>
    <form method="post" id="basket-form" action="https://kite.trade/connect/basket">
    <input type="hidden" name="api_key" value="7xxxxxaxxuxxrigy" />
    <input type="hidden" id="basket" name="data" value="" />
    <input type="submit" value="Submit"> //button-submit
    </form>

    <script>
    console.log("i was called");
    function send(){
    var your_basket=[{
    "tradingsymbol": "INFY",
    "exchange": "NSE",
    "transaction_type": "BUY",
    "order_type": "MARKET",
    "quantity": 10
    }];
    document.getElementById("basket").value =JSON.stringify(your_basket);
    document.getElementById("basket-form").submit();
    };
    </script>
    </body>
    </html>
    output :
    Same Result :(

    For your reference Please have a look :
    https://jsfiddle.net/ayxfLdj9/1/

    Can you correct the code and post
  • rakeshr
    @raaghulr
    You have defined send() JS method but aren't calling the same when the Submit button is clicked.
    You need to call send() when submit button is clicked,as shown below:
    <input type="submit" value="Submit" onclick="send()">
  • raaghulr
    @rakeshr
    {"status":"error","message":"Invalid connect session.","data":null,"error_type":"InputException"}

    Now different error, "Invalid Connect Session" first error was "Invalid orders payload", first error resolved, but new error came. Thanks for your effort, Please have a look
  • rakeshr
    @raaghulr
    Working fine for me.Can you check fiddle code here and make the changes ?
  • raaghulr
    @rakeshr
    Thanks, Working now :smiley:
This discussion has been closed.