Content-type of postback API

ACV
What is the Content-type that is sent to postback url?

In the documentation, it is mentioned it is sent as a raw JSON, however when I deployed my app, I get the below error
HttpMediaTypeNotSupportedException: Content-Type 'application/x-www-form-urlencoded;charset=UTF-8' is not supported

Currently my endpoint can handle 'Content-Type: application/json'
Tagged:
  • sujith
    It is a form post request and payload data is a json.
  • ACV
    Using x-www-form-urlencoded also didn’t work for me
    @sujith Could you share a sample curl command
  • sujith
    You may refer to this thread.
  • ACV
    I finally got it working, although i find this implementation non standard.

    If anyone else is looking to implement this here is a sample curl & implementation in spring
    curl --location 'https://website/postback' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data '{
    "user_id": "AB1234",
    "unfilled_quantity": 0,
    "app_id": 1234,
    "checksum": "2011845d9348bd6795151bf4258102a03431e3bb12a79c0df73fcb4b7fde4b5d",
    "placed_by": "AB1234",
    "order_id": "220303000308932",
    "exchange_order_id": "1000000001482421",
    "parent_order_id": null,
    "status": "COMPLETE",
    "status_message": null,
    "status_message_raw": null,
    "order_timestamp": "2022-03-03 09:24:25",
    "exchange_update_timestamp": "2022-03-03 09:24:25",
    "exchange_timestamp": "2022-03-03 09:24:25",
    "variety": "regular",
    "exchange": "NSE",
    "tradingsymbol": "SBIN",
    "instrument_token": 779521,
    "order_type": "MARKET",
    "transaction_type": "BUY",
    "validity": "DAY",
    "product": "CNC",
    "quantity": 1,
    "disclosed_quantity": 0,
    "price": 0,
    "trigger_price": 0,
    "average_price": 470,
    "filled_quantity": 1,
    "pending_quantity": 0,
    "cancelled_quantity": 0,
    "market_protection": 0,
    "meta": {},
    "tag": null,
    "guid": "XXXXXX"
    }'

    @PostMapping(path = "/orderUpdate")
    public void orderUpdate(HttpServletRequest request) {
    String rawRequestBody = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
    String postbackString = URLDecoder.decode(rawRequestBody, StandardCharsets.UTF_8);
    PostbackData postbackData = objectMapper.readValue(postbackString, PostbackData.class);
    if (validatePostbackData(postbackData)) {

    }
    }

    private boolean validatePostbackData(PostbackData postbackData) {
    String shaFromKite = postbackData.getChecksum();
    String myKey = postbackData.getOrder_id() + postbackData.getOrder_timestamp() + apiSecret;
    String shaFromMe = org.apache.commons.codec.digest.DigestUtils.sha256Hex(myKey);
    return shaFromKite.equals(shaFromMe);
    }
This discussion has been closed.