Skip to content

Instantly share code, notes, and snippets.

@TimSC
Last active November 28, 2022 14:06
Show Gist options
  • Save TimSC/a562e801237665d55bb824ac834e56d0 to your computer and use it in GitHub Desktop.
Save TimSC/a562e801237665d55bb824ac834e56d0 to your computer and use it in GitHub Desktop.
Example for using opencart user API
<?php
// User API usage in OpenCart 3.0.2.0
// http://sv2109.com/en/article/opencart-api-system
// Patches from https://forum.opencart.com/viewtopic.php?t=186063 need to be applied to 3.0.2.0
$apiKey = "foobar34y3yl34myl3erwhyl34yl3k4ynpwgen"; //Whatever you put in System -> Users -> API
$url = "http://server/opencart/upload/index.php?route=api/login&api_token=0";
$curl = curl_init($url);
$post = array (
'username' => 'MonitorSales',
'key' => $apiKey
);
curl_setopt_array( $curl, array(
CURLOPT_RETURNTRANSFER=> TRUE,
CURLOPT_POSTFIELDS => $post
) );
$raw_response = curl_exec( $curl );
//var_dump($raw_response);
$response = json_decode($raw_response);
curl_close($curl);
var_dump($response);
$api_token = $response->api_token;
$url = "http://server/opencart/upload/index.php?route=api/cart/products&api_token=".$api_token;
$post = array (
);
$curl = curl_init($url);
$raw_response = curl_exec( $curl );
var_dump($raw_response);
@aytenpulcu
Copy link

"key" is a reserved word in MySQL, so naming a table column key in the opencart api table is astonishing - obviously the api is broken - but how can it work for anyone even, with such a fundamental error?

Fatal error: Uncaught Exception: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key =
Do you find any solution this problem ? I have same error, Can you give any advice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment