Click here to Skip to main content
15,843,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have below code for one of my clients e-commerce website and I have integrated shipping API to it but after integrating it is giving me error and a PopUp when the code is executed.

$shipment['waybill'] = '123456789'; // waybill number
            $shipment['name'] = $order_info['shipping_firstname'] . " " . $order_info['shipping_lastname']; // consignee name
            $shipment['order'] = $order_id; // client order number
            $shipment['products_desc'] = $product['name'];
            $shipment['order_date'] = date(DATE_ISO8601, strtotime($order_info['date_added'])); // ISO Format date(DATE_ISO8601, strtotime($order_info['date_added']));
            $shipment['payment_mode'] = $pay_check_bhavik;
            $shipment['total_amount'] = (double)($order_total_for_delhivery); // in INR
            $shipment['cod_amount'] = $order_total_for_delhivery; // amount to be collected, required for COD
            $shipment['add'] = $order_info['shipping_address_1'] . " " . $order_info['shipping_address_2']; // consignee address
            $shipment['city'] = $order_info['shipping_city'];
            $shipment['state'] = $order_info['shipping_zone'];
            $shipment['country'] = $order_info['shipping_country'];
            $shipment['phone'] = $order_info['telephone'];
            $shipment['pin'] = $order_info['shipping_postcode'];
            $shipment['quantity'] = $product['quantity']; // quanitity of quantity
            $shipment['seller_name']='seller'; //name of seller
            $shipment['seller_add']='add of seller'; // add of seller
            $shipment['seller_cst'] = 'cst no of seller'; //cst number of seller
            $shipment['seller_tin'] = 'tin no of seller';  //tin number of seller
            $shipment['seller_inv']= 'invoice_number'; // invoice number of shipment
            $shipment['seller_inv_date']= '2013-04-08T18:30:00+00:00'; // ISO Format
            // pickup location information //
            $pickup_location['add'] = '113 Barthal, Dundahera';
            $pickup_location['city'] = 'New Delhi';
            $pickup_location['country'] ='India';
            $pickup_location['name'] = 'CLIENT WAREHOUSE';  // Use client warehouse name
            $pickup_location['phone'] = '011-23456245';
            $pickup_location['pin'] = '110070';
            $pickup_location['state'] = 'Delhi';
            $shipments = array($shipment);
            $package_data['shipments'] = $shipments;
            $package_data['pickup_location'] = $pickup_location;
            $params['format'] = 'json';
            $params['data'] =json_encode($package_data);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($params));
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
            $result_shipping_delhivery = curl_exec($ch);


Now I am not getting where the error is initiating and in which variable I am getting the JSON from the API. Error is "SyntaxError: Unexpected token{"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900