How to Cancel and Reorder Customer Order in Magento 2 Using REST API

magento2.2.4rest api

I would like to add the options to the customer to cancel their orders and Re-order option for the desired products at customer dashboard.

By using REST API, How can i cancel and reorder items?

Please check the following attachment for the reference.

enter image description here

Best Answer

Magento already have an in build api point by which you can cancel an order

http://www.example.com/rest/V1/orders/78/cancel

where 78 is an order id

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://example.com/rest/V1/orders/1/cancel",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer qctyw0k8uc7svw6m7hwwl58ws3twymts",
    "cache-control: no-cache",
    "content-type: application/json",
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
Related Topic