1

I am getting the following error while updating the record using the Magento 2 REST API.

Error:

( [message] => Request does not match any route. [trace] => )

I am explaining my code below.

$customerData = [
        'customer' => [
            "id" => 25,
            "email" => "subhra@email.com",
            "firstname" => "subhrajy",
            "lastname" => "pradhan",
            "storeId" => 1,
            "websiteId" => 1,
             "customAttributes" => [
        ],

        "addresses" => [

        ]
    ],
        "password" => "subhra123@"
    ];

    $headers = array("Authorization: Bearer $token"); 
    $requestUrl='http://hostapp.com/index.php/rest/V1/customers/25';


    $ch = curl_init();
    $ch = curl_init($requestUrl); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customerData));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . $token));   
    $result = curl_exec($ch); 

    $result = json_decode($result, 1);
    echo '<pre>';print_r($result);

Here I trying to update only the password using entity_id and getting the above error. I am using the postman and setting the PUT method there. Here I need to update those data for a customer.

  • Please update full code – jafar pinjar Aug 22 '18 at 18:43
  • may I know your magento 2 version? – kunj Aug 23 '18 at 5:15
  • you're passing array keys in wrong multidimensional order. – Aditya Shah Aug 30 '18 at 5:48
0

It seems you've not configured CURLOPT_POSTFIELDS correctly for PUT in your curl, replace

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customerData));

with

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(json_encode($customerData)));

and it should work fine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.