1

I have been trying to update a field on a customer information via the REST API using this link format:

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

But to I am getting a customer email already exist

How can I update information via REST API..

Sample Code:

        $productData = json_encode(array(
            'id'        => 1,
            'firstname' => 'Ted',
            'lastname'  => 'Mosbius',
            'website_id'=> 1,
            'group_id'     => 1,
            'email'         => '[email protected]'
        ));
        $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

Thanks in advance

1
  • I am asking, because unfortunately , I haven't found any docs or guide on doing this... Commented Nov 19, 2012 at 9:17

2 Answers 2

2

Just found the problem, I need to use PUT instead of POST when updating based from this link (http://ajaxpatterns.org/RESTful_Service)...

$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... :)

Sign up to request clarification or add additional context in comments.

1 Comment

After getting $productsList how to get product other details like category, name, manufacture etc.
0

Errors do come up less the header is formed like this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.