Postbacks seem fine from our end. I don't think we are sending postbacks in the above-mentioned format like enclosed JSON enclosed inside other curly braces.
@sujith indeed the postback payload received is malformed JSON. I see what @quadcodes has mentioned on my newly implemented nodejs backend.
This is the error I get when I try to parse the json in JavaScript with JSON.parse() method. SyntaxError: Unexpected token o in JSON at position 1
Here is the exact payload I received at postback URL route.
{ '{"placed_by":"PLACEHOLDER","order_id":"PLACEHOLDER","exchange_order_id":"","parent_order_id":"","status":"REJECTED","status_message":"RMS:Blocked for OPTSTK MKT nse_fo broker- ZERODHA Remarks: Option Stock market orders are not allowed block type: ALL","order_timestamp":"2018-09-22 12:07:40","exchange_update_timestamp":"","exchange_timestamp":"","variety":"regular","exchange":"NFO","tradingsymbol":"MARUTI18SEP8500CE","instrument_token":19073538,"order_type":"MARKET","transaction_type":"BUY","validity":"DAY","product":"NRML","quantity":75,"disclosed_quantity":0,"price":0,"trigger_price":0,"average_price":0,"filled_quantity":0,"pending_quantity":0,"cancelled_quantity":0,"market_protection":0,"tag":"","guid":"PLACEHOLDER","user_id":"PLACEHOLDER","unfilled_quantity":0,"app_id":PLACEHOLDER,"checksum":"PLACEHOLDER"}': '' }
If you observe carefully, the initial { ' part and ending part ': '' } are causing JSON to be malformed.
I am not able to proceed because I expect the API payload to be well formed for further processing such as request authentication. Have you not received similar reports from others? I am bit surprised that this is broken since more than 1 month.
@sujith I am receiving similar error that @quadcodes is receiving on my newly implemented Node.JS backend.
There is what I get SyntaxError: Unexpected token o in JSON at position 1
The payload received on backend for postback URL: { '{"placed_by":"PLACEHOLDER","order_id":"PLACEHOLDER","exchange_order_id":"","parent_order_id":"","status":"REJECTED","status_message":"RMS:Blocked for OPTSTK MKT nse_fo broker- ZERODHA Remarks: Option Stock market orders are not allowed block type: ALL","order_timestamp":"2018-09-22 12:07:40","exchange_update_timestamp":"","exchange_timestamp":"","variety":"regular","exchange":"NFO","tradingsymbol":"MARUTI18SEP8500CE","instrument_token":19073538,"order_type":"MARKET","transaction_type":"BUY","validity":"DAY","product":"NRML","quantity":75,"disclosed_quantity":0,"price":0,"trigger_price":0,"average_price":0,"filled_quantity":0,"pending_quantity":0,"cancelled_quantity":0,"market_protection":0,"tag":"","guid":"PLACEHOLDER","user_id":"PLACEHOLDER","unfilled_quantity":0,"app_id":PLACEHOLDER,"checksum":"PLACEHOLDER"}': '' }
If you notice carefully in payload, the starting portion '{" and ending portion ': '' } need not be there and are causing JSON to be malformed.
I am surprised that no one has reported this and probably that's why this is still broken. Can you please look into it?
Is it consistent? We just tried and it seems fine. Can you mention, if you are using some third party library or give a brief description of the implementation here?
If someone still stumbles upon this problem - Postback event received on webhook is having Content-Type set as application/x-www-form-urlencoded. If you're expecting application/json, you'll be having parsing issues like above. 1. Set the content-type for webhook as application/x-www-form-urlencoded and make your API compatible for it., or 2. If you're using expressjs, implement a middleware which does this parsing job for you, or 3. If you're using loopbackjs (specifically), add this line inside start function in your server.js file
I don't think we are sending postbacks in the above-mentioned format like enclosed JSON enclosed inside other curly braces.
This is the error I get when I try to parse the json in JavaScript with JSON.parse() method.
SyntaxError: Unexpected token o in JSON at position 1
Here is the exact payload I received at postback URL route.
{ '{"placed_by":"PLACEHOLDER","order_id":"PLACEHOLDER","exchange_order_id":"","parent_order_id":"","status":"REJECTED","status_message":"RMS:Blocked for OPTSTK MKT nse_fo broker- ZERODHA Remarks: Option Stock market orders are not allowed block type: ALL","order_timestamp":"2018-09-22 12:07:40","exchange_update_timestamp":"","exchange_timestamp":"","variety":"regular","exchange":"NFO","tradingsymbol":"MARUTI18SEP8500CE","instrument_token":19073538,"order_type":"MARKET","transaction_type":"BUY","validity":"DAY","product":"NRML","quantity":75,"disclosed_quantity":0,"price":0,"trigger_price":0,"average_price":0,"filled_quantity":0,"pending_quantity":0,"cancelled_quantity":0,"market_protection":0,"tag":"","guid":"PLACEHOLDER","user_id":"PLACEHOLDER","unfilled_quantity":0,"app_id":PLACEHOLDER,"checksum":"PLACEHOLDER"}': '' }
If you observe carefully, the initial { ' part and ending part ': '' } are causing JSON to be malformed.
I am not able to proceed because I expect the API payload to be well formed for further processing such as request authentication. Have you not received similar reports from others? I am bit surprised that this is broken since more than 1 month.
Please fix.
There is what I get
SyntaxError: Unexpected token o in JSON at position 1
The payload received on backend for postback URL:
{ '{"placed_by":"PLACEHOLDER","order_id":"PLACEHOLDER","exchange_order_id":"","parent_order_id":"","status":"REJECTED","status_message":"RMS:Blocked for OPTSTK MKT nse_fo broker- ZERODHA Remarks: Option Stock market orders are not allowed block type: ALL","order_timestamp":"2018-09-22 12:07:40","exchange_update_timestamp":"","exchange_timestamp":"","variety":"regular","exchange":"NFO","tradingsymbol":"MARUTI18SEP8500CE","instrument_token":19073538,"order_type":"MARKET","transaction_type":"BUY","validity":"DAY","product":"NRML","quantity":75,"disclosed_quantity":0,"price":0,"trigger_price":0,"average_price":0,"filled_quantity":0,"pending_quantity":0,"cancelled_quantity":0,"market_protection":0,"tag":"","guid":"PLACEHOLDER","user_id":"PLACEHOLDER","unfilled_quantity":0,"app_id":PLACEHOLDER,"checksum":"PLACEHOLDER"}': '' }
If you notice carefully in payload, the starting portion '{" and ending portion ': '' } need not be there and are causing JSON to be malformed.
I am surprised that no one has reported this and probably that's why this is still broken. Can you please look into it?
We just tried and it seems fine.
Can you mention, if you are using some third party library or give a brief description of the implementation here?
Postback event received on webhook is having
Content-Type
set asapplication/x-www-form-urlencoded
. If you're expectingapplication/json
, you'll be having parsing issues like above.1. Set the content-type for webhook as
application/x-www-form-urlencoded
and make your API compatible for it., or2. If you're using expressjs, implement a middleware which does this parsing job for you, or
3. If you're using loopbackjs (specifically), add this line inside start function in your server.js file