1
votes

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 ?

1
Have you added use statement for the controller? I cannot know the exact reason without seeing the code. - Vipulw
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 - Ziko10

1 Answers

3
votes

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
        }
    }
  )