Trying to add to cart functionality in my custom php code using shopify ajax api. My code is below for which getting error code 401.
Anybody can give me example of how use the Shopify ajax apis or solve problem in code below in php code.
CODE:
<?php
session_start();
require __DIR__.'/vendor/autoload.php';
use phpish\shopify;
require __DIR__.'conf.php';
$shopify = shopify\client(SHOPIFY_SHOP, SHOPIFY_APP_API_KEY, SHOPIFY_APP_PASSWORD, true);
try
{
$add = $shopify('POST /cart/add.js',array(), array
(
'cart' => array
(
"quantity" => 2,
"id" => 3908511558
)
));
echo "<pre>";
print_r($add);
echo "</pre>";
}
catch(shopify\ApiException $e)
{
echo $e;
echo "<pre>";
print_R($e->getRequest());
print_R($e->getResponse());
echo "</pre>";
}
catch(shopify\CurlException $e)
{
echo $e;
echo "<pre>";
print_R($e->getRequest());
print_R($e->getResponse());
echo "</pre>";
}
?>
ERROR:
phpish\shopify\ApiException: [401] Unauthorized
cart/add.jsonly work in shopify store environment, not external pages.cart/add.jsnot belong to the shopify api