简体   繁体   English

Magento REST API更新

[英]Magento REST API Updating

I have been trying to update a field on a customer information via the REST API using this link format: 我一直在尝试使用以下链接格式通过REST API更新客户信息上的字段:

http://<magentohost>/api/rest/customers

But to I am getting a customer email already exist 但是要我收到客户电子邮件已经存在

How can I update information via REST API.. 如何通过REST API更新信息。

Sample Code: 样例代码:

        $productData = json_encode(array(
            'id'        => 1,
            'firstname' => 'Ted',
            'lastname'  => 'Mosbius',
            'website_id'=> 1,
            'group_id'     => 1,
            'email'         => 'ted@mosbis.com'
        ));
        $headers = array('Content-Type' => 'application/json');
        $oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_POST, $headers);
        // $oauthClient->fetch($resourceUrl);
        $productsList = json_decode($oauthClient->getLastResponse());
        print_r($productsList);

In this code, email exist, id exist , website_id exist and group_id exist... I just wanted to update the firstName and lastName 在此代码中,电子邮件存在,id存在,website_id存在,group_id存在...我只想更新firstName和lastName

Thanks in advance 提前致谢

Just found the problem, I need to use PUT instead of POST when updating based from this link (http://ajaxpatterns.org/RESTful_Service)... 刚发现问题,根据此链接(http://ajaxpatterns.org/RESTful_Service)更新时,我需要使用PUT而不是POST ...

$productData = json_encode(array(
    'id'        => 1,
    'firstname' => 'Ted',
    'lastname'  => 'Mosbius',
));
$headers = array('Content-Type' => 'application/json');
$oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_PUT, $headers);
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);

Hopefully this will help someone in the future... :) 希望这会在将来对某人有所帮助... :)

出现错误的情况很少,报头是这样形成的:

$headers = array('Content-Type' => 'application/json', 'Accept' => '*/*');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM