cancel
Showing results for 
Search instead for 
Did you mean: 

%fieldName is required, what went wrong?

%fieldName is required, what went wrong?

 

I am a student making my final project to graduate. i am new to Magento 2 but have tried working with it's API using PHP.

 

I am trying to write some code that updates the order status. however this error keeps getting in the way. i have tried online but have no luck in uncovering the underlying issue. This is said error:

 ["message"]=> string(59) ""%fieldName" is required. Insert it and try again.["parameters"]=> array(1) { ["fieldName"]=> string(13) "statusHistory" }


what is going wrong? what am i missing? what can i do to avoid this error in the future?

<?php
$id = "000000002";
$ch = curl_init("<base_url>/rest/all/V1/orders/{$id}/comments");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
	'Accept: application/json',
	'Content-Type: application/json',
	'Authorization: Bearer <token>',
]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array([
  "statusHistory"=> [
    "comment"=> "string",
    "created_at"=> "string",
    "entity_id"=> 0,
    "entity_name"=> "string",
    "is_customer_notified"=> 0,
    "is_visible_on_front"=> 0,
    "parent_id"=> 0,
    "status"=> "string",
    "extension_attributes"=> []
  ] 
])));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_exec($ch);
// $info = curl_getinfo($ch);
// print_r($info['request_header']);
$response = curl_exec($ch);
$decoded_response = json_decode($response,true);
curl_close($ch);
var_dump($decoded_response);

?>

 

 

2 REPLIES 2

Re: %fieldName is required, what went wrong?

if you want to change the order status 

Check this api {{your url}}rest/V1/orders and apply following params to update status

{
    "entity": {
        "entity_id": orderid,
        "state":"processing",
        "status": "processing"
    }
}

Re: %fieldName is required, what went wrong?

You are Sending POST Request so you also have to send data in POST request in json format like :{ "id": {}}

And have to set

Content-Type:application/json

in http header.

 

Volkswagen Credit