Getting error while Add to Cart programmatically with custom options
<p>I am trying to Add Products to Cart with respect to customer (programmatically) but getting error "Invalid request for adding product to quote". I have both Simple products (with custom options) and configurable products. Below is my code. Please help. Many thanks in advance.</p>

<pre><code>public function addtocartAction(){
try {
    $cusId = $this-&gt;getRequest()-&gt;getParam('cusId');
    $customer = Mage::getModel('customer/customer')-&gt;load($cusId);
    $quote = Mage::getModel('sales/quote')-&gt;loadByCustomer($customer);
    $quoteId = $quote-&gt;getId();
    //$products = $this-&gt;getRequest()-&gt;getParam('products');
    $products = json_decode('[{"proId": "906","proQty": "1", "options":{"17":"wq","16":"18"}}]');

    foreach($products as $product) {
        /*if (!$product-&gt;getId()) {
            throw new Exception();
        }*/
        foreach ($product-&gt;options as $optKey =&gt; $optValue) {
            $optAll[$optKey] = $optValue;
        }

        $mainProduct = Mage::getModel('catalog/product')-&gt;load($product-&gt;proId);
        $params = array(
            'product' =&gt; $product-&gt;proId,
            'qty'     =&gt; $product-&gt;proQty,
            'options' =&gt; $optAll
        );
        echo "&lt;pre /&gt;"; print_r($params);
        $quote-&gt;addProduct($mainProduct, $params);
        $quote-&gt;setIsActive(1);
        $quote-&gt;collectTotals()-&gt;save();
    }
    $rslt['success'] = '1';
    $rslt['message'] = 'Product has been succefully added to cart';
}
catch(Exception $e){
    $rslt['success'] = '0';
    $rslt['message'] = $e-&gt;getMessage();
}
print_r(json_encode($rslt));
</code></pre>

<p>}</p>