Post by CreeperFace » Mon Feb 03, 2020 3:32 am

Hi I'm trying to access the API on localhost but getting this error everytime.

my code I'm testing the API with (Also tested with curl CLI)

Code: Select all

function do_curl_request($url, $params=array()) {
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
//    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

    $params_string = '';
    if (is_array($params) && count($params)) {
        foreach($params as $key=>$value) {
            $params_string .= $key.'='.$value.'&';
        }
        rtrim($params_string, '&');

        curl_setopt($ch,CURLOPT_POST, count($params));
        curl_setopt($ch,CURLOPT_POSTFIELDS, $params_string);
    }

    //execute post
    $result = curl_exec($ch);

    //close connection
    curl_close($ch);

    return $result;
}

//$url = 'http://opencart.localhost.tld/index.php?route=api/comparison/notify&token=nevimtoken';
$url = 'http://opencart.localhost.tld/index.php?route=api/cart/products';

$fields = array(
    'username' => 'comparison',
    'key' => 'jR8pLkqIXZdfTAEGbWRdBpi8aLSElhc5nObiqBjEF1EZBTzT2RX8lBVkSq6w0F6LaTrTnuP5MdILWBZIUCmusJR5yXT7bIoHAdxkcMVeOb83GlpUMpCx3xg71ohqQKnfar4BOfp38M4giwNe7mKMQxDV53fSXleTMvRUmVRwHulcOwCUUiXvZ5Tdzje2x6CtbF5JhFj81tYd1kjfPwyQSsUt5XAGT1pLsaQ1TEyAmF2XtcqSSa56XkOysKuZdjrA',
);

$json = do_curl_request($url, $fields);
var_dump($json);
I've tried to follow these steps and also went through probably all the similar threads
*************************************************
System > User > API
1 Created API Example : " Main IP "
2 Click on Generate API
3 Make it Enable
Click on API Addressees
Click on ADD IP
Copy paste your IP
Click on Save

System > Setting > Edit Your main Store > Click on Option tab
API User
Select " main IP "
*************************************************

Also tried to add IPv6 but without success

Newbie

Posts

Joined
Mon Feb 03, 2020 3:06 am

Post by straightlight » Mon Feb 03, 2020 6:50 am

The OC version has not been posted. The api/products.php file has not been posted either. The posted code on the above is incomplete. The API ID with the backward compatibility method is missing. You need to refer to the admin/controller/sale/order.php file. Look for:

Code: Select all

new Session
You should find the whole paragraph about the API login. In addition, what error message are you getting?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by CreeperFace » Tue Feb 04, 2020 12:54 am

Excuse me, my OC version is 3.0.3.2. My issue description is quite missleading, since what I've found recently. The problem is that my session ID (OCSESSID) gets changed with every request for some reason. No matter what API class I call (login, order, cart or my own one).

EDIT: fixed it by changing token parameter to api_token (referring to an older OC version)

Newbie

Posts

Joined
Mon Feb 03, 2020 3:06 am

Post by straightlight » Tue Feb 04, 2020 5:16 am

CreeperFace wrote:
Tue Feb 04, 2020 12:54 am
Excuse me, my OC version is 3.0.3.2. My issue description is quite missleading, since what I've found recently. The problem is that my session ID (OCSESSID) gets changed with every request for some reason. No matter what API class I call (login, order, cart or my own one).

EDIT: fixed it by changing token parameter to api_token (referring to an older OC version)
You were probably referring to this step: viewtopic.php?f=202&t=211613&p=754456&h ... en#p754454 and viewtopic.php?f=202&t=211613&p=754456&h ... en#p754456 . This has been patched on my behalf and on Github last year.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: JessiesBoutique, pprmkr and 500 guests