Post by richardkong » Sat Aug 22, 2015 6:15 pm

I have encountered this problem too. I have also read numerous threads where people have experienced the same problem, but there has been no sure way to resolve this. So, I spent a few hours stepping through the code to understand what was going on.

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.
Here is a high level overview of the process that the code goes through when adding a new order history:

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
After Click "Add history"
  • 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.
In my case, on my production server, my API user was just disabled. I enabled it and all was good. On my development machine, I was running opencart HTTPS on port 888. Opencart is hard coded to use 443, so it could not login as the API error. The fix would have been to fix the code to read the port number from the config file, but i'm ok with it not working on my development machine.

Newbie

Posts

Joined
Sat Aug 22, 2015 5:42 pm

Post by rmullaney77 » Fri Sep 04, 2015 8:59 am

Worked fine as long as you remember to set Status to Enabled, error persists otherwise (most overlooking that detail).
Admin > System > Users > API
  • No users?
    • Add
    • Enter a username (using "api" is fine)
    • Generate
    • Status: Enabled
    • Save
  • All disabled?
    • Edit
    • Status: Enabled
    • Save
Admin > System > Settings > Edit > Option (tab) > Checkout (section)
  • API User: [api user from above]
  • Save
Admin > Sales > Order > Edit
Tested on 2.0.3.1.

Note to Daniel, Q, or whoever: This should done automatically during install/upgrade if required to modify orders.

--------------------------------------------------
My BlogMy ExtensionsOpenCart Templates


User avatar
Active Member

Posts

Joined
Fri Nov 19, 2010 2:08 am
Location - Tampa, Florida

Post by MediaCityWay » Fri Sep 11, 2015 10:35 pm

I just came across the same problem everyone else seems to be having, here's each step I took to fixing the problem, it may seem like other solutions but follow this step by step. It takes about 2 mins if that.

1. Go to Settings > Users > API
Now delete any and all API users. Once complete add a new API, the username can be anyting you like go for something like STORENAMEApiUser, then click the generate button to give yourself a password then finally make sure status is enabled, once you've done that click save.

2. Just the same as the other solutions go to System > Store > Edit > Option and under checkout make sure the Api user you just created is selected in the API User dropdown box.

3. Now to make it work, go in to your admin config file, mine when I first looked into it looked like this:
define('HTTP_SERVER', 'http://STORENAME.com/admin/');
define('HTTP_CATALOG', 'http://STORENAME.com/');

// HTTPS
define('HTTPS_SERVER', 'http://STORENAME.com/admin/');
define('HTTPS_CATALOG', 'http://STORENAME.com/');

Even though I am currently not using a SSL certifacte change the HTTPS settings to read:

// HTTPS
define('HTTPS_SERVER', 'https://STORENAME.com/admin/');
define('HTTPS_CATALOG', 'https://STORENAME.com/');

Upload the admin config file to its correct location on the server and reload your admin page (or log out and in again) and try updating your order history, works perfectly.

Newbie

Posts

Joined
Sat Jan 11, 2014 2:28 am

Post by hpmon » Tue Sep 22, 2015 3:43 am

having the same issue OP had. Turned SSL on, and I'm using htaccess (only so that a certain IP can access admin). Would these be causing the issue? Not a big deal, but would rather having it working properly.

Newbie

Posts

Joined
Sat Aug 29, 2015 2:24 am

Post by hpmon » Wed Sep 30, 2015 12:17 am

gonna bump because I'm still having the issue. Created the API, changed config, still nothing.

Newbie

Posts

Joined
Sat Aug 29, 2015 2:24 am

Post by ramudovari » Mon Oct 05, 2015 3:49 pm

This is bug... I am trying so many ways but still not working.

Newbie

Posts

Joined
Fri Oct 02, 2015 3:42 pm

Post by ledstyle » Sun Oct 11, 2015 3:44 am

I have the same problems...

I made that order.php change to shop/system/modification/admin/controller/sale/order.php
as it says in ERROR code that problem was there.
If I change it to under shop/Admin/...order.php it didn't change anything.
When did change to that first address then the ERROR code changes only to Syntax error. syntaxerror... as earlier there was long code of error.

I checked API thru phpmyadmin, everything ok and same.
I made new API and cleaned all others...no help.

And I use SSLs on my site so I checked config.php ,both...are ok..

still getting errors

Newbie

Posts

Joined
Sat Oct 10, 2015 7:55 pm

Post by oz457 » Thu Oct 22, 2015 6:16 am

I have the same problem. I am not using SSL. I also cannot edit any of the orders. When I use API, and I want to go to the Order list, I get a blank page instead.

This bug is really blocking my entire upgrade. I have done everything to the letter, but nothing works. I hope a solution will follow soon.

New member

Posts

Joined
Wed Oct 28, 2009 5:33 am

Post by sunsys » Thu Oct 22, 2015 7:12 am

oz457 wrote:I have the same problem. I am not using SSL. I also cannot edit any of the orders. When I use API, and I want to go to the Order list, I get a blank page instead.

This bug is really blocking my entire upgrade. I have done everything to the letter, but nothing works. I hope a solution will follow soon.
The only one issue really faced in 2031 is the curl loop back issue that is the one that is causing all these things to happen. I faced the same issues on VPS hosting using NGINX but the moment I shifted out from VPS to normal hosting with the very same installation all my problems were solved and the very same oc-2031 runs like a hare now. I really don't why you people keep on with the same thing again and again, move to version 2101 and get on with your work all issues(curl loop back) encountered here have been cleared in 2101 so why not use that. This is my 2 bit worth of info though.

Regards,
Sun Systems
Industrial Electronics and Instrumentation


User avatar
Active Member

Posts

Joined
Tue Jan 27, 2015 5:19 am

Post by oz457 » Thu Oct 22, 2015 8:03 am

I'd love to go to move forward to oc-2.1.0.1 but the upgrade does not work. Too many issues with database stuff. I'm doing an upgrade from an 'old' 1.5.6.4 in my test environment.
oc.2.0.3.1 does give the curl loopback issue,
oc.2.1.0.1 has no waterproof upgrade scripts.
I tried to upgrade to 2.1.0.1 the other day but nothing worked.

I might test to upgrade 2.0.3.1 to 2.1.0.1 tomorrow, I'll report back, but I don't expect good results.

New member

Posts

Joined
Wed Oct 28, 2009 5:33 am

Post by sunsys » Thu Oct 22, 2015 8:56 am

oz457 wrote:I'd love to go to move forward to oc-2.1.0.1 but the upgrade does not work. Too many issues with database stuff. I'm doing an upgrade from an 'old' 1.5.6.4 in my test environment.
oc.2.0.3.1 does give the curl loopback issue,
oc.2.1.0.1 has no waterproof upgrade scripts.
I tried to upgrade to 2.1.0.1 the other day but nothing worked.

I might test to upgrade 2.0.3.1 to 2.1.0.1 tomorrow, I'll report back, but I don't expect good results.
Forget upgrades, we all know that it does not work in oc.
A simple suggestion would be to first read and study, shifting from 1564 and/or 2031 to 2101 is not big deal. You can study the changes done in the database tables in the 3 versions and then you can very easily do the transfer, go slow take one baby step at a time and believe me it is very much doable I have done it and I am not a software guy by miles so you too can easily do it. Download Neuhoffs Import/Export tool(great bit of software) do an export first and use that to study the database table structure, proceed slowly and you will surely get there, do a complete backup of your site from cpanel(zip or tar) as well as database from myphpadmin(sql) to have a fall back option.
You will be able to do it 100%, OC is nice and easy.

Regards,
Sun Systems
Industrial Electronics and Instrumentation


User avatar
Active Member

Posts

Joined
Tue Jan 27, 2015 5:19 am

Post by oz457 » Thu Oct 22, 2015 8:14 pm

Tried to upgrade to 2.1.0.1 but it comes with tons of database errors. As I noticed, the upgrade scripts are not working well.
I don't understand why the opencart staff doesn't look into this Undefined variable issue. I have seen literally hundred of freelance jobs for this issue on www.freelancer.com.

Strange that the staff doesn't really work on it.

New member

Posts

Joined
Wed Oct 28, 2009 5:33 am

Post by oz457 » Thu Oct 22, 2015 9:42 pm

ISSUE RESOLVED

I don't know what went wrong, but you cannot install Opencart as long you don't have CURL installed.
For some reason, CURL got uninstalled during the process.
And that was the reason why I couldn't get the orders updated.

The issue was resolved by doing this on the Ubuntu machine:

sudo apt-get install php5-curl
sudo /etc/init.d/apache2 restart

I had some help from a freelance programmer on the freelancer.com website to find this out. All credits go to
https://www.freelancer.com/u/ntiersolutions.html
to find the solution.

New member

Posts

Joined
Wed Oct 28, 2009 5:33 am

Post by usopencart » Fri Nov 13, 2015 3:17 am

MediaCityWay wrote:MediaCityWay
:) This solution worked for me. Thank you for saving me a great deal of time.

Newbie

Posts

Joined
Fri Nov 13, 2015 3:14 am

Post by fisher05 » Sun Nov 15, 2015 9:59 pm

I found the issue to be spaces in the config.php directory

e.g. define('HTTP_SERVER', 'http://localhost:8888/test cart/admin/');

change to:

define('HTTP_SERVER', 'http://localhost:8888/test_cart/admin/');

change your directory to be named test_cart as well.

Worked for me :)

Fisher05


User avatar
New member

Posts

Joined
Wed May 22, 2013 1:30 am

Post by elitza85 » Mon Nov 16, 2015 2:20 am

Vicx007 wrote:
ashwani_multi wrote:I got the same error and i fixed it

go to Admin->System->users->Api

Add a new api generate password, and enable it

Then go to Admin->system->settings->Edit->Option(tab)

Select api user under Checkout section as your api user

Then save the changes

Then go to Sales->orders->edit

It will work fine :-)
I did this but still it didnt work can anyone help its annoying it has been two whole night i havent slept plssssssssssss :bash: :bash: :bash: :bash: :bash: :bash:

Hi,
I see that you struggled the same error as me a few months ago. I use 2.0.2.0 fresh install. Did you find any resolution and what?

Thanks,
Elitsa

Newbie

Posts

Joined
Fri Nov 13, 2015 11:48 pm

Post by Weckie » Sun Nov 22, 2015 12:22 am

We are running the newest opencart 2.1.0.1 and facing this very same issue when generating invoices.
A popup comes with this message: SyntaxError: JSON Parse error: Unexpected EOF

We have no clue what this can be.

It's a shop not even live, we are building from scratch, and during testing we face this problem.

Thanks for any help.

Using opencart 2.1.0.1
Quite new to opencart :P


User avatar
Newbie

Posts

Joined
Thu Nov 19, 2015 4:01 am
Location - The Netherlands

Post by craigt » Tue Nov 24, 2015 7:40 pm

Thanks MediaCityWay - your solution worked perfectly for me. We were missing the "https" even though we don't use SSL yet.

Newbie

Posts

Joined
Fri Jul 17, 2015 2:10 am

Post by hebiki » Wed Nov 25, 2015 3:35 pm

anyone else have luck with this? I'm 2.0.3.1.... just upgraded from 1.5.6.4.

ive tried all the solutions above, my code is identical to MediaCityWay's code.. and still no luck.

New member

Posts

Joined
Sun Oct 10, 2010 4:00 pm

Post by pacage » Sat Nov 28, 2015 4:52 am

I have the same issue and have tried everything on this thread.

It appears to be a very generic error with many possible causes.
A huge bug in OpenCart's error reporting/handling if you ask me.

It looks as though I'm going to have to find another cart solution as OpenCart is just too costly when it comes to fault finding. Which is a pity because I really like OpenCart when it works. :(

Newbie

Posts

Joined
Thu Jul 02, 2015 3:52 am
Who is online

Users browsing this forum: No registered users and 28 guests