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" => "[email protected]",
            "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.

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

1 Answer 1

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.

Your Answer

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

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