Register

Author Topic: API problems - What you need to know  (Read 13821 times)

Randem

  • Administrator
  • Hero Member
  • *****
  • Posts: 2686
API problems - What you need to know
« Reply #1 on: January 28, 2016, 10:47:21 PM »
        When you start to have API problems, and at one time or another you will (unless you are really lucky).
These are the reasons you may have it along with how to fix it. It is a relatively simple problem but it is hidden by AJAX calls.
Since you cannot see what is happening; this can be a maddening problem because the errors do not show in the system error log.

The errors are such:

  • Your IP address does not have permission to use API (even though your IP address is in the API table).

  • You get an error message pop-up that just says Error Undefined.

  • You cannot edit or you get errors on certain orders (URL's may not be in database or may not resolve to the correct IP Address or folder).

        I will first go thru the issues that make this type of thing happen.
In your multi-store settings you have URL's that not only do not resolve to the same IP address but they also have to resolve to the same folder
on the same server. This can happen on multi-store setups but is more prevalent on multi-store conversions (upgrades) than anything else or stores that have been moved from a folder to the root or vice-versa.
There should be no way for this to happen on a single store setup unless it was changed from multi-store to single store and it had previous orders from the other stores or the store was moved to a different location
and there were orders with the address of the old location stored in the orders table. This is also why it only appears when you attempt to edit orders. I was informed by OSWorX to add another possible element in things like this happening because one has edited a language or source file and saved it in the incorrect format (BOM or/and as ANSII instead of UTF-8). Of course when the system reads this file it will be incomplete and can cause all sort of other misdeeds also.

        OpenCart somehow gets the wrong URL of a store from one of it queries and if the URL points to another folder on your hosted system, this is where the fun begins...
The AJAX calls use the bad URL to make it's call to login, The login fails because the AJAX call is attempting to run code in the incorrect folder.
Now the interesting part of this is if you actually have an index.php file in that folder it will execute that code; which can cause unpredictable results on your system.
Now when the call returns or times out, it failed and you get the message that your IP address is not permitted to use API.
You can go thru the exercise of creating a new API, assigning it to your store etc... as many times as you like and none of it will matter; you will continue to get the same error (this is when you start to curse uncontrollably).

To fix do the following:

  • Change all store URLs to point to the same IP address and the same folder on your hosted server. All URL's MUST be unique for proper operation. You may need to setup additional test URL's to for the different stores to accomplish this. ALL STORE URL's MUST BE TERMINATED WITH A TRAILING SLASH!

  • Setup the API for your default store.

  • Change you store settings to select the new API

  • All multi-stores should be the same protocol, force to HTTP or HTTPS. Do not mix the two, bad results will transpire. Change your config.php files (Root & Admin folders).

  • Change all URL's in the orders table that do not resolve to the correct location to one that does.

  • Change all folders and filenames that will be part of the URL NOT to have any spaces in them.


Other Helpful Information