1

I want to use custom identifier in a custom action without using {id} like this .

 @ApiResource(
   itemOperations={
     "FORGOT-PASSWORD"={
        "method"="PUT",
        "path"="/users/{forgotPasswordToken}/forgot-password",
        "controller"="App\Controller\ForgotPasswordController",
        "defaults"={"identifiedBy"="forgotPasswordToken"}
        }
    }
  )

But i still have the same error with "Invalid identifier value or configuration" .

Any issue please ?

2
  • Have you added use statement for the controller? I cannot know the exact reason without seeing the code. Commented Nov 18, 2019 at 12:23
  • Hello thank you for your response, the controller works well but the request doesn't work because in custom action you can only get a resources with it's ID and not with another attribute like {forgotPasswordToken} in my case Commented Nov 18, 2019 at 13:23

1 Answer 1

4

It's because Api Platform have a Read listener that try to retrieve the entity link to your item operation.

For your custom action you don't have identifier in your path like {id} to identify your resource, so the solution is to desactive the read listener with something like this :

@ApiResource(
   itemOperations={
     "FORGOT-PASSWORD"={
        "method"="PUT",
        "path"="/users/{forgotPasswordToken}/forgot-password",
        "controller"="App\Controller\ForgotPasswordController",
        "defaults"={"identifiedBy"="forgotPasswordToken"},
        "read"=false
        }
    }
  )
Sign up to request clarification or add additional context in comments.

2 Comments

Yes but with this solution i can't acces to the new data (password) in my controller like this class ForgotPasswordController { public function __invoke(User $user, EntityManagerInterface $entityManager, Request $request) { var_dump($request->get('newPassword')); die; } }
Yes you have to retrieve it manualy or if your token is persisted directly in your User entity with the property forgotPasswordToken may be you can add it as identifier but I don't know if you can have multiple identifiers on the same resource (never tried it)

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.