Magento 2 Rest API顺序编辑

Magento 2 Rest API顺序编辑,rest,magento2,guzzle,Rest,Magento2,Guzzle,我想知道在我请求订单后如何编辑订单。 无论订单是否导出,我都创建了一个自定义属性 我首先获取状态为“未导出”的所有订单,在导出它们之后,我想将自定义属性更改为“已导出” 编辑/更新订单的REST请求是什么?我不断收到错误消息,如: {"message":"%fieldName is a required field.","parameters": {"fieldName":"entity"} 这是我的代码: $json = array( "entity_id" =>

我想知道在我请求订单后如何编辑订单。 无论订单是否导出,我都创建了一个自定义属性

我首先获取状态为“未导出”的所有订单,在导出它们之后,我想将自定义属性更改为“已导出”

编辑/更新订单的REST请求是什么?我不断收到错误消息,如:

{"message":"%fieldName is a required field.","parameters":
{"fieldName":"entity"}
这是我的代码:

    $json = array(
        "entity_id" => $id, 
        "extension_attributes" => array(
            "custom_export_attribute" => "exported",
            )
        );
    $webapi = new ApiClient('https://dev.local.nl', self::$username, self::$password); 
    $response = $webapi->getClient()->request('PUT', '/rest/V1/orders/create', [

        'headers'   => [                
            'Authorization'             => "Bearer " . $webapi->getToken(),
            'Content-Type'              => "application/json"
        ],
        'body'     => json_encode($json)

    ]);    
    return json_decode($response->getBody(), true);
我还尝试:

 $webapi->getClient()->request('PUT', '/rest/V1/orders/'.$id,

要编辑/更新订单详细信息,Magento 2
/V1/orders
接受
POST
请求方法。根据,它接受以下格式的请求正文(您可以在文档页面中找到整个JSON请求):

因此,您只需将
$json
变量更新为:

$json = [
    "entity"=> [
        "entity_id" => $id,
        "extension_attributes" => [
            "custom_export_attribute" => "exported"
        ]
    ]
]
然后使用
POST
请求方法而不是
PUT
调用。在我的建议中,我更喜欢使用新订单创建

$json = [
    "entity"=> [
        "entity_id" => $id,
        "extension_attributes" => [
            "custom_export_attribute" => "exported"
        ]
    ]
]