Reputation: 700
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
Upvotes: 1
Views: 754
Reputation: 406
Errors do come up less the header is formed like this:
$headers = array('Content-Type' => 'application/json', 'Accept' => '*/*');
Upvotes: 0
Reputation: 700
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... :)
Upvotes: 2