2

i have created REST Api how can i use those REST Api directly from helper?

Curl call is a option is there any other method that we can use?

2
  • 2
    We can directly use interfaces for communication between modules Commented Feb 27, 2019 at 11:52
  • can you please explain with example?
    – user75757
    Commented Feb 27, 2019 at 12:50

1 Answer 1

1

Generally we need to use /V1/integration/customer/token to access token if we need to generate token internal purpose we can just use the interface directly as below:

public function __construct(
    \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService

) {
    $this->customerTokenService = $customerTokenService;

}

public function sample(string $email, string $password)
{

    $token = $this->customerTokenService->createCustomerAccessToken($email, $password);
}

in di.xml

 <route url="/V1/integration/customer/token" method="POST">
    <service class="Magento\Integration\Api\CustomerTokenServiceInterface" method="createCustomerAccessToken"/>
    <resources>
        <resource ref="anonymous"/>
    </resources>
</route>

We can use Service class and method defined for any other APIS

2
  • How we can use that methods directly from helper?
    – user75757
    Commented Feb 28, 2019 at 5:57
  • 2
    You can Inject the interface in constructor and use the methods define in it Commented Feb 28, 2019 at 6:01

Your Answer

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