{ "status": "error", "message": "Missing or empty field `exchange`", "data": null, "error_type": "In

sb1314
sb1314 edited September 18 in .Net API client
data = "exchange=NFO&tradingsymbol=NIFTY1991911000PE&transaction_type=BUY&quantity=75&price=45.5&product=MIS&order_type=LIMIT&validity=day"

UrlPrint=UrlReturnVal("https://api.kite.trade/orders/regular?" & data,"POST","data","Yes")

buy order Using Kite Connect error shows { "status": "error", "message": "Missing or empty field `exchange`", "data": null, "error_type": "InputException" }

  • sb1314
    sb1314 edited September 18
    pls u too refer this im getting same error code is perfect



    <%

    Dim data,UrlPrint
    Set oJSON = New aspJSON


    if Request.QueryString("out") = "Logout" then

    UrlPrint=UrlReturnVal("https://api.kite.trade/session/token?api_key=" & Request.Cookies("Kite-API")("api_key") & "&access_token=" & Request.Cookies("Kite-API")("access_token"),"Delete","","No")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.data("status") & "<br>"

    if oJSON.data("status") = "success" then

    Response.Cookies("Kite-API")("access_token")=""
    Response.Cookies("Kite-API")("User_ID")=""
    Response.Cookies("Kite-API")("api_key")=""
    Response.Cookies("Kite-API")("login_time")=""
    Response.Cookies("Kite-API")=""
    Response.Cookies("Kite-API").Expires = Now()
    session.Abandon
    Response.Expires=-1
    Response.AddHeader "Pragma", "no-cache"
    Response.AddHeader "Cache-Control", "no-store"

    end if

    Response.Write oJSON.JSONoutput()

    elseif Request.QueryString("out") = "Profile" then

    UrlPrint=UrlReturnVal("https://api.kite.trade/user/profile?api_key=zfu63d25jhlx4lhi","GET","","Yes")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.JSONoutput()

    elseif Request.QueryString("out") = "Margin" then

    UrlPrint=UrlReturnVal("https://api.kite.trade/user/margins?api_key=zfu63d25jhlx4lhi","GET","","Yes")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.JSONoutput()

    elseif Request.QueryString("out") = "Buy" then


    'data = "exchange=NFO&tradingsymbol=NIFTY1991911000PE&transaction_type=BUY&quantity=1&price=829.85&product=MIS&order_type=MARKET&validity=day"

    data = "exchange=NSE&tradingsymbol=INFY&transaction_type=BUY&quantity=1&price=829.9&product=NRML&order_type=MARKET"

    UrlPrint=UrlReturnVal("https://api.kite.trade/orders/regular?" & data,"POST","data","Yes")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.JSONoutput()

    elseif Request.QueryString("out") = "Sell" then

    data = "exchange=NFO&tradingsymbol=NIFTY1991911000PE&transaction_type=SELL&quantity=75&price=45.5&product=MIS&order_type=LIMIT&validity=day"

    UrlPrint=UrlReturnVal("https://api.kite.trade/orders/regular","POST","data","Yes")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.JSONoutput()

    elseif Request.QueryString("out") = "Modify" then

    data = "price=64.000"

    UrlPrint=UrlReturnVal("https://api.kite.trade/orders/regular/" & Request("id") & data,"PUT","data","Yes")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.JSONoutput()

    elseif Request.QueryString("out") = "Cancel" then

    UrlPrint=UrlReturnVal("https://api.kite.trade/orders/regular/" & Request("id"),"DELETE","","Yes")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.JSONoutput()

    elseif Request.QueryString("out") = "ListAllorder" then

    UrlPrint=UrlReturnVal("https://api.kite.trade/orders","GET","","Yes")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.JSONoutput()

    elseif Request.QueryString("out") = "ListThisOrder" then

    UrlPrint=UrlReturnVal("https://api.kite.trade/orders/" & Request.QueryString("id") & "/","GET","","Yes")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.JSONoutput()

    elseif Request.QueryString("out") = "I" then

    UrlPrint=UrlReturnVal("https://api.kite.trade/instruments","GET","","Yes")

    oJSON.loadJSON(UrlPrint)

    Response.Write oJSON.JSONoutput()

    end if

    Function UrlReturnVal(Url,Method,PostData,HeadReq)

    Dim httpRequest, postResponse

    Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
    httpRequest.Open Method, Url, False

    if HeadReq="Yes" then

    httpRequest.SetRequestHeader "X-Kite-Version", "3"
    httpRequest.SetRequestHeader "Authorization", "token " & Request.Cookies("Kite-API")("api_key") & ":" & Request.Cookies("Kite-API")("access_token")

    end if

    if Method = "POST" Then
    httpRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    httpRequest.setRequestHeader "Content-Length", len(PostData)
    httpRequest.Send PostData
    else
    httpRequest.Send
    end if

    postResponse = httpRequest.ResponseText

    UrlReturnVal=postResponse

    'response.write postResponse

    End Function


    %>
  • sb1314
    still same error
    data = "exchange=NFO&tradingsymbol=NIFTY1991911000PE&transaction_type=BUY&quantity=1&price=829.85&product=NRML&order_type=LIMIT&validity=day&tag=tyu&variety=regular"
  • sb1314
    sb1314 edited September 18
    Post to https://api.kite.trade/orders/regular?exchange=NFO&tradingsymbol=NIFTY1991911000PE&transaction_type=BUY&quantity=75&price=200.85&product=NRML&order_type=MARKET&validity=day&tag=tyu&variety=regular failed with 400
    {"status":"error","message":"Missing or empty field `exchange`","data":null,"error_type":"InputException"}
    Bad Request 400 error kindly help me
  • sujith
    This is a post request which accepts params in the form body. You seem to be sending query params.
  • sb1314
    bro pls check i sends params using form body also kindly help

    data = "exchange=NSE&tradingsymbol=INFY&transaction_type=BUY&quantity=1&price=829.9&product=NRML&order_type=MARKET"

    UrlPrint=UrlReturnVal("https://api.kite.trade/orders/regular?" & data,"POST","data","Yes")

    Function UrlReturnVal(Url,Method,PostData,HeadReq)

    Dim httpRequest, postResponse

    Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
    httpRequest.Open Method, Url, False

    if HeadReq="Yes" then

    httpRequest.SetRequestHeader "X-Kite-Version", "3"
    httpRequest.SetRequestHeader "Authorization", "token " & Request.Cookies("Kite-API")("api_key") & ":" & Request.Cookies("Kite-API")("access_token")

    end if

    if Method = "POST" Then
    httpRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    httpRequest.setRequestHeader "Content-Length", len(PostData)
    httpRequest.Send PostData
    else
    httpRequest.Send
    end if


    postResponse = httpRequest.ResponseText

    UrlReturnVal=postResponse

    'response.write postResponse

    End Function
Sign In or Register to comment.