0

In magento 1.9.1 .0 I have made a few REST APIs and they work very well in my local machine. But When I moved the code to hosting environment, it is giving me 302 status code. I supposed the api itself is not working but while debugging I found that api functions well but in browser I get 302. A Similar question is here 302 Moved Temporarily. Googled much but nothing helped me!

How can I get it working? I welcome all constructive suggestions.Thanks a lot!

1 Answer 1

0

By 302 that means you get redirected. You need to play around with your restapi url. For example your default rest api url looks like these: http://magentohost/api/rest/

But your hosting for example has a redirect to www, then your link should looks like that http://www.magentohost/api/rest/

Maybe you site using https then the correct link will be something like https://magentohost/api/rest/

Or maybe your hosting used index.php for the controller generated links? Then the correct link to your rest api should be http://magentohost/index.php/api/rest/

Just play around with your rest api url and you should be fine with the solution.

4
  • Thanks for your answer! @electroid. Surely I check the urls of api. By the way, when I used echos and exits in the api file it echoed the values correctly and I got it working. But it didn't work when I run usually. So eventually I placed an exit(0) at the end of the api, next to the actual echo statement which throws back some data. And it worked well. is this a good practice? Feb 21, 2017 at 9:03
  • @velavasimmanarumugan, place your code, please.
    – electroid
    Feb 22, 2017 at 9:10
  • sorry but which code exactly, the api POST call or actual api code? Feb 22, 2017 at 11:21
  • @velavasimmanarumugan, your rest api call please.
    – electroid
    Feb 22, 2017 at 14:27

Your Answer

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

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