1

I have installed an module thats working fine. I tried to run this modules API via Swagger and I am able to run from there.

Now I want to implement this modules API in my custom module and I tried below code but it didn't work and I m getting error -

$userData = array("username" => "muusername", "password" => "mypassword");
$ch = curl_init("http://127.0.0.1/git_projects/magento/index.php/rest/V1/integration/admin/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));

$token = curl_exec($ch);

$ch = curl_init("http://127.0.0.1/git_projects/magento/rest/default/V1/productAttachment");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));

$result = curl_exec($ch);

var_dump($result);

I also tried with my 'Integration' user's token that I created via admin.

But with above code I am getting error -
"{"message":"Request does not match any route.","trace":null}"

I am running above code in my controller's execute function.

Note - Currently In API calling I am not passing any parameter. Its just for test. It should give 'parameter' respective error but its giving different error.

Please help me in this -

Your Answer

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

Browse other questions tagged or ask your own question.