Cancel order not working through API

below code success but not effect in firststock demat account…

please help us

public async Task CancelOrder(OrderModel inputModel)
{
//return await ExitBankNiftyPosition(inputModel);

 UserRespModel ObjUserRespModel = await GetJkeyByLoggingIn();

 if (string.IsNullOrWhiteSpace(ObjUserRespModel.data.susertoken))
     return "unable to get susertoken for CancelOrder";

 if (string.IsNullOrWhiteSpace(inputModel.orderNumber))
     return "orderNumber is mandatory for CancelOrder";

 var client = new ClsHttpClientCalling();
 {
     string response = "";

     CancelOrderModel inputCancelOrderModel = new CancelOrderModel();
     inputCancelOrderModel.userId = ObjUserRespModel.data.actid;
     inputCancelOrderModel.jKey = ObjUserRespModel.data.susertoken;
     inputCancelOrderModel.orderNumber = inputModel.orderNumber;

     //var inputs = new
     //{
     //    userId = ObjUserRespModel.data.actid,
     //    jKey = ObjUserRespModel.data.susertoken,
     //    orderNumber = inputModel.orderNumber // Replace with the PE order's ID
     //    //exchange = "NFO",

     //};

     //  inputs.orderNumber = inputModel.orderNumber;

     /*Document Information as JSON*/
     HttpContent content = new StringContent(JsonConvert.SerializeObject(inputCancelOrderModel));

     content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
     try
     {
         response = await client.APICallandGetResponse("https://connect.thefirstock.com/api/V4/squareOffPosition", HttpAction.POST, content);
         ObjUserRespModel = JsonConvert.DeserializeObject<UserRespModel>(response);

         if (ObjUserRespModel.status == "success")
         {
             return "CancelOrder done";
         }
         else
         {
             return response;
         }
     }
     catch (Exception ex)
     {                    //Adding response data in error, then we will know whats the content in the response message.                    ex.Data.Add("Response String", response);                    throw ex;                }            }
         return "CancelOrder failed - " + ex.Message;

     }

 }

}

public class CancelOrderModel
{
    public string userId { get; set; }
    public string jKey { get; set; }
    public string orderNumber { get; set; }

}

Hi Pavan,

The issue is that the wrong API endpoint is being used for canceling the order.

:no_entry_sign: Incorrect: https://connect.thefirstock.com/api/V4/squareOffPosition
:white_check_mark: Correct: https://connect.thefirstock.com/api/V4/cancelOrder

Please refer to the official documentation for the correct API usage: Cancel Order API Docs

Using the correct endpoint should resolve the issue. Let me know if you need any further assistance!