문제

I have custom API in which I am retrieving customer balance as:

use Magento\CustomerBalance\Model\BalanceFactory;
........................
........................
$model = $this->balanceFactory->create()->setCustomerId($customerId)->loadByCustomer();
$customerBalance = $model->getAmount();

In postman request is send as:

http://127.0.0.1/rest/V1/mymodule/request/R1

and output is correct logged in customer balance.

But when I test same API in Magento swagger UI, here the Curl appears is:

curl -X POST "http://127.0.0.1/index.php/rest/all/V1/mymodule/request/R1" -H "accept: application/json" -H "Authorization: Bearer nbvkrjkewuiu398hds"

which has extra index.php/rest/all/

and from response the customer balance is shown as 0 always.

What is the reason of different output on testing same API in Default Swagger and then in Postman ?

Any help will be highly appreciated!

도움이 되었습니까?

해결책

I figured it, we need to provide store code in url to get right response from swagger.

For Example in my case I provided it as:

http://127.0.0.1/swagger?store=default

This returns the output same as we get by Postman/Insomnia

Reference: https://devdocs.magento.com/guides/v2.3/rest/generate-local.html#generate-a-full-rest-reference-locally

Please upvote if it helps you for the ease of upcoming readers.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top