I want to update order status to complete using webapi
here is my testing code :
$data = array (
'entity' =>
array (
'entity_id' => $id,
'status' => 'complete',
),
);
$this->generateApiToken();
$ch = curl_init("https://$this->link/rest/V1/orders/");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json",
"Authorization: Bearer " . json_decode($this->token) ));
$cusJsonData = curl_exec($ch);
and when this code runs, the status updated correctly , but the increment_id changed.
Can anyone help me with this problem?
Please refer below URL for Magento 2 API. I guess there is no such specific API to update order status to complete.
URL: https://devdocs.magento.com/swagger/#/
Go to salesOrderRepositoryV1 or salesOrderManagementV1.
I've just had this on v2.2.5, and put it down to a bug in Magento's API.
To get round this, you need to specify the original increment_id
along with the entity_id
when doing status updates.
Your JSON should look similar to this:
{
"entity": {
"entity_id":23,
"increment_id":"0000000153",
"state":"processing",
"status":"processing"
}
}
Also, not sure why state
and status
is required, I just chalk this up to Magento's awful API.