0

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!

1 Answer 1

0

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.