I am on Opencart 2.0.3.1
tl;dr;
There are two main things that can go wrong.
- The default API user that is set is disabled or missing
To fix, either create a new API user or reenable the existing user that the setting table referred to.
When creating a new user make sure you go into the database to update the setting table to point to the new user
If reenabling the user, make sure that you are enabling the user that is referenced in the setting table - Opencart is unable to login as your API user.
The mostly likely culprit is your SSL configuration. Opencart will always use port 443 (default ssl port) so if your SSL is running on a different port then it Opencart will not be able to login. Or, your host might not support https loopback connections. Opencart is trying to connect back to itself.
This part happens sometime before the button is clicked
- Retrieve the api user for the store, this is stored in the database where the value in the setting table corresponds to the api_id in the api table
Code: Select all
select * from setting where `key` = 'config_api_id'; select * from api;
- Opencart will actually login using the API user, and use this user to execute any changes
- Check that the API user is set and that the API user is logged in. If either of these checks fail we get the "undefined json" error since $json is only set if the next steps are completed.
- Build up a HTTP command based on the data you have put into the form
- HTTP command is posted to the API endpoint the url will be something like
Code: Select all
https://www.mystore.com/admin/index.php?route=sale/order/api&token=78943d0bdb071e512ea71fc17180b1b8&api=api/order/history&order_id=18
- Store the response back from the API into $json and return it to the webpage you clicked on the "Add history" button
- The contents of $json is just a success/fail message. Javascript on the page will handle the response and show you success/fail message on the page.