<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>shiprocket API Archives - Cody Paste</title>
	<atom:link href="https://www.codypaste.com/tag/shiprocket-api/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codypaste.com/tag/shiprocket-api/</link>
	<description>THE WEB PLAYGROUND</description>
	<lastBuildDate>Tue, 03 Jan 2023 09:11:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://www.codypaste.com/wp-content/uploads/2022/12/cropped-codypaste-32x32.png</url>
	<title>shiprocket API Archives - Cody Paste</title>
	<link>https://www.codypaste.com/tag/shiprocket-api/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Shiprocket API in PHP CodeIgniter</title>
		<link>https://www.codypaste.com/shiprocket-api-in-php-codeigniter/</link>
					<comments>https://www.codypaste.com/shiprocket-api-in-php-codeigniter/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Tue, 03 Jan 2023 08:06:53 +0000</pubDate>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[create token in shiprocket]]></category>
		<category><![CDATA[shiprocket]]></category>
		<category><![CDATA[shiprocket API]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=845</guid>

					<description><![CDATA[<p>Signup in Shiprocket Shiprocket API implementation in PHP is so easy, Here we will use CodeIgniter Framework, We will see two processes: &#160; Courier to Customer To create order/Send a courier through API we have to request cURL &#8220;https://apiv2.shiprocket.in/v1/external/orders/create/adhoc&#8221; with &#8220;token&#8220;. Pickup From Customer To Create &#8216;Return&#8217; through API we have to request cURL &#8220;https://apiv2.shiprocket.in/v1/external/orders/create/return&#8221; &#8230; </p>
<p class="link-more"><a href="https://www.codypaste.com/shiprocket-api-in-php-codeigniter/" class="more-link">read more<span class="screen-reader-text"> "Shiprocket API in PHP CodeIgniter"</span></a></p>
<p>The post <a href="https://www.codypaste.com/shiprocket-api-in-php-codeigniter/">Shiprocket API in PHP CodeIgniter</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.shiprocket.in/" target="_blank" rel="noopener">Signup in Shiprocket</a></p>
<p>Shiprocket API implementation in PHP is so easy, Here we will use CodeIgniter Framework,</p>
<p>We will see two processes:</p>
<p>&nbsp;</p>
<ol>
<li><span style="font-size: 1rem;"><span style="font-size: 1rem;"><span style="font-size: 18pt; color: #ff6600;"><strong>Courier to Customer</strong></span><br />
To create order/Send a courier through API we have to request cURL &#8220;<span style="color: #008000;"><em>https://apiv2.shiprocket.in/v1/external/orders/create/adhoc</em></span>&#8221; with &#8220;<span style="color: #ff6600;"><strong>token</strong></span>&#8220;.</span></span></li>
<li><strong><span style="font-size: 18pt; color: #ff6600;">Pickup From Customer</span><br />
</strong>To Create &#8216;Return&#8217; through API we have to request cURL &#8220;<span style="color: #008000;"><em>https://apiv2.shiprocket.in/v1/external/orders/create/return</em></span>&#8221; with &#8220;<span style="color: #ff6600;"><strong>token</strong></span>&#8220;.</li>
</ol>
<p><strong><span style="font-size: 1rem;">We will see how to create and send token in cURL below.</span></strong></p>
<p>So let&#8217;s get started.</p>
<h3><strong>Create a Token in Shiprocket:</strong></h3>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">public function shiprocketAuth(){
        $curl = curl_init();
        curl_setopt_array($curl, array(
          CURLOPT_URL =&gt; 'https://apiv2.shiprocket.in/v1/external/auth/login',
          CURLOPT_RETURNTRANSFER =&gt; true,
          CURLOPT_ENCODING =&gt; '',
          CURLOPT_MAXREDIRS =&gt; 10,
          CURLOPT_TIMEOUT =&gt; 0,
          CURLOPT_FOLLOWLOCATION =&gt; true,
          CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
          CURLOPT_CUSTOMREQUEST =&gt; 'POST',
          CURLOPT_POSTFIELDS =&gt;'{
            "email": "info@codypaste.com",
            "password": "asdfgadf9876^%$"
        }',
          CURLOPT_HTTPHEADER =&gt; array(
            'Content-Type: application/json'
          ),
        ));
        $tknresponse = curl_exec($curl);
        curl_close($curl);
        $tknres =   json_decode($tknresponse, true);
        $tokenRes   = $tknres['token'];
        return $tokenRes;
    }</pre><p>This method/Function will return Token, wiil use this token to &#8216;Create&#8217; and &#8216;Pickup&#8217; on both process.</p>
<p><em><strong>Note: Please update CURLOPT_POSTFIELDS value email and password with your detail.</strong></em></p>
<p>&nbsp;</p>
<p>So, here you can see complete code example below.</p>
<p>===================================================</p>
<h2><strong>Controller</strong></h2>
<p>Create a file <strong>application/controllers/Shiprocket.php</strong> with given code below</p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Shiprocket extends CI_Controller {

	public function __construct(){
	    error_reporting(0);
        parent::__construct();
        $this-&gt;load-&gt;library(array('form_validation','session','cart'));
		//$this-&gt;load-&gt;database();
    }
	
	public function index(){
		$this-&gt;load-&gt;view('shiprocketView');
	}

	public function shiprocketAuth(){
        $curl = curl_init();
        curl_setopt_array($curl, array(
          CURLOPT_URL =&gt; 'https://apiv2.shiprocket.in/v1/external/auth/login',
          CURLOPT_RETURNTRANSFER =&gt; true,
          CURLOPT_ENCODING =&gt; '',
          CURLOPT_MAXREDIRS =&gt; 10,
          CURLOPT_TIMEOUT =&gt; 0,
          CURLOPT_FOLLOWLOCATION =&gt; true,
          CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
          CURLOPT_CUSTOMREQUEST =&gt; 'POST',
          CURLOPT_POSTFIELDS =&gt;'{
            "email": "info@codypaste.com",
            "password": "asdfgadf9876^%$"
        }',
          CURLOPT_HTTPHEADER =&gt; array(
            'Content-Type: application/json'
          ),
        ));
        $tknresponse = curl_exec($curl);
        curl_close($curl);
        $tknres =   json_decode($tknresponse, true);
        $tokenRes   = $tknres['token'];
        return $tokenRes;
    }
	
	public function shiprocketSendToCustomer(){		
		$order_id				=   "CODYPASTE-01"; // Unique order id
		$order_date				=   "2022-12-14"; // Current date, YY-MM-DD
		$channel_id				=   "123456"; // From Shiprocket Panel, Login to shiprocket dashboard
		$billing_customer_name	=  "Vipul"; // Courier Receiver Name
		$billing_last_name		=   "Rai"; // Courier Receiver Last Name
		$billing_address		=   "401, Frinds Enclave"; // Courier Receiver
		$billing_address_2		=   "Shahberi"; // Courier Receiver
		$billing_city			=   "Noida"; // Courier Receiver
		$billing_state			=   "Uttarpradesh"; // Courier Receiver		
		$billing_pincode		=   "201009";		
		$billing_email			=   "info@asd.com";
		$billing_phone			=   "9999999999";		
		$name					=   "Cody Paste T-Shirt"; // Product name
		$sku					=   "CPTS-01"; // Product SKU
		$units					=   "1"; // Number of product
		$selling_price			=   "450"; // Price of product
		$discount				=   "0"; // discount of product
		$payment_method			=   "Prepaid";
		$sub_total				=   "450"; // Subtotal of product
		$length					=   "30"; // in centimeter
		$breadth				=   "25"; // in centimeter
		$height					=   "10"; // in centimeter
		$weight					=   "1.59";	//in Kilogram (KG)	
		
		$tokenRes   = $this-&gt;shiprocketAuth();
		$curl 		= curl_init();
		curl_setopt_array($curl, array(
		  CURLOPT_URL =&gt; 'https://apiv2.shiprocket.in/v1/external/orders/create/adhoc',
		  CURLOPT_RETURNTRANSFER =&gt; true,
		  CURLOPT_ENCODING =&gt; '',
		  CURLOPT_MAXREDIRS =&gt; 10,
		  CURLOPT_TIMEOUT =&gt; 0,
		  CURLOPT_FOLLOWLOCATION =&gt; true,
		  CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
		  CURLOPT_CUSTOMREQUEST =&gt; 'POST',
		  CURLOPT_POSTFIELDS =&gt;'{
			"order_id": "'.$order_id.'",
			"order_date": "'.$order_date.'",
			"pickup_location": "Primary",
			"channel_id": "'.$channel_id.'",
			"comment": "Cody Paste",
			"billing_customer_name": "'.$billing_customer_name.'",
			"billing_last_name": "'.$billing_last_name.'",
			"billing_address": "'.$billing_address.'",
			"billing_address_2": "'.$billing_address_2.'",
			"billing_city": "'.$billing_city.'",
			"billing_pincode": '.$billing_pincode.',
			"billing_state": "'.$billing_state.'",
			"billing_country": "India",
			"billing_email": "'.$billing_email.'",
			"billing_phone": "'.$billing_phone.'",
			"shipping_is_billing": true,
			"shipping_customer_name": "Cody Paste",
			"shipping_last_name": "",
			"shipping_address": "",
			"shipping_address_2": "",
			"shipping_city": "",
			"shipping_pincode": "",
			"shipping_country": "",
			"shipping_state": "",
			"shipping_email": "",
			"shipping_phone": "",
			
			"order_items": [
			{
			  "sku": "'.$sku.'",
			  "name": "'.$name.'",
			  "units": '.$units.',
			  "selling_price": '.$selling_price.',
			  "discount": '.$discount.',
			  "qc_enable":false,
			  "hsn": "",
			  "brand":"",
			  "qc_size":""
			   }
			],
			"payment_method": "'.$payment_method.'",
			"shipping_charges": 0,
			"giftwrap_charges": 0,
			"transaction_charges": 0,
			"total_discount": 0,
			"sub_total": '.$sub_total.',
			"length": '.$length.',
			"breadth": '.$breadth.',
			"height": '.$height.',
			"weight": '.$weight.'
			}',
		  CURLOPT_HTTPHEADER =&gt; array(
			'Content-Type: application/json',
			'Authorization: Bearer '.$tokenRes.''
		  ),
		));
		
		$response = curl_exec($curl);
		
		curl_close($curl);
	}
	
	public function shiprocketPickupFromCustomer(){
		$order_id                   =   "CODYPASTE-02"; // Unique order id
		$order_date                 =   "2022-12-14"; // Current date, YY-MM-DD
		$channel_id                 =   "123456"; // From Shiprocket Panel, Login to shiprocket dashboard
		$pickup_customer_name       =   "Vipul"; // Customer name, from whre you want to pickup
		$pickup_last_name           =   "Rai"; // Customer
		$pickup_address             =   "401, Living Homes";
		$pickup_address_2           =   "Friends Enclave";
		$pickup_city                =   "Noida";
		$pickup_state               =   "Uttarpradesh";		
		$pickup_pincode             =   "201009";
		$pickup_email               =   "vips.rai@gmail.com";
		$pickup_phone               =   "9999999999";
		$shipping_customer_name     =   "Cody Paste"; // Name of Courier Sender.
		$shipping_address           =   "345, Canaught Place";
		$shipping_address_2         =   "Kamala Market";
		$shipping_city              =   "New Delhi";
		$shipping_country           =   "India";
		$shipping_pincode           =   "110033";
		$shipping_state             =   "Delhi";
		$shipping_email             =   "info@codypaste.com";
		$shipping_phone             =   "8989899878";
		$order_items                =   "/";
		$name                       =   "Cody Paste T-Shirt"; // Order Product Name
		$sku                        =   "CPTS01"; // Product SKU
		$units                      =   "1"; // Number of products
		$selling_price				=   "450"; // Price of product
		$discount					=   "0"; // discount of product
		$payment_method				=   "Prepaid";
		$sub_total					=   "450"; // Subtotal of product
		$length						=   "30"; // in centimeter
		$breadth					=   "25"; // in centimeter
		$height						=   "10"; // in centimeter
		$weight						=   "1.59";	//in Kilogram (KG)	
		
		$tokenRes   = $this-&gt;shiprocketAuth();
		$curl = curl_init();
		curl_setopt_array($curl, array(
		  CURLOPT_URL =&gt; 'https://apiv2.shiprocket.in/v1/external/orders/create/return',
		  CURLOPT_RETURNTRANSFER =&gt; true,
		  CURLOPT_ENCODING =&gt; '',
		  CURLOPT_MAXREDIRS =&gt; 10,
		  CURLOPT_TIMEOUT =&gt; 0,
		  CURLOPT_FOLLOWLOCATION =&gt; true,
		  CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
		  CURLOPT_CUSTOMREQUEST =&gt; 'POST',
		  CURLOPT_POSTFIELDS =&gt;'{
			"order_id": "'.$order_id.'",
			"order_date": "'.$order_date.'",
			"channel_id": "'.$channel_id.'",
			"pickup_customer_name": "'.$pickup_customer_name.'",
			"pickup_last_name": "'.$pickup_last_name.'",
			"company_name":"Cody Paste",
			"pickup_address": "'.$pickup_address.'",
			"pickup_address_2": "'.$pickup_address_2.'",
			"pickup_city": "'.$pickup_city.'",
			"pickup_state": "'.$pickup_state.'",
			"pickup_country": "India",
			"pickup_pincode": '.$pickup_pincode.',
			"pickup_email": "'.$pickup_email.'",
			"pickup_phone": "'.$pickup_phone.'",
			"pickup_isd_code": "91",
			"shipping_customer_name": "'.$shipping_customer_name.'",
			"shipping_last_name": "",
			"shipping_address": "'.$shipping_address.'",
			"shipping_address_2": "'.$shipping_address_2.'",
			"shipping_city": "'.$shipping_city.'",
			"shipping_country": "India",
			"shipping_pincode": '.$shipping_pincode.',
			"shipping_state": "'.$shipping_state.'",
			"shipping_email": "'.$shipping_email.'",
			"shipping_isd_code": "91",
			"shipping_phone": '.$shipping_phone.',
			"order_items": [
			{
			  "sku": "'.$sku.'",
			  "name": "'.$name.'",
			  "units": '.$units.',
			  "selling_price": '.$selling_price.',
			  "discount": '.$discount.',
			  "qc_enable":false,
			  "hsn": "",
			  "brand":"",
			  "qc_size":""
			   }
			],
			"payment_method": "'.$payment_method.'",
			"total_discount": "0",
			"sub_total": '.$sub_total.',
			"length": '.$length.',
			"breadth": '.$breadth.',
			"height": '.$height.',
			"weight": '.$weight.'
			}',
		  CURLOPT_HTTPHEADER =&gt; array(
			'Content-Type: application/json',
			'Authorization: Bearer '.$tokenRes.''
		  ),
		));
		
		$response = curl_exec($curl);
		
		curl_close($curl);
		//echo $response;
    		    
	}
	
	
}</pre><p><span style="color: #ff0000;"><em>(Please go through every line of code to understand the variable values and other things)</em></span></p>
<h2><strong>View</strong></h2>
<p>Create a file <strong>application/views/shiprocketView.php</strong> with given code below</p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
defined('BASEPATH') OR exit('No direct script access allowed');
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
	&lt;meta charset="utf-8"&gt;
	&lt;title&gt;Shiprocket&lt;/title&gt;	
&lt;/head&gt;
&lt;body&gt;

&lt;div id="container"&gt;
	&lt;form action="&lt;?php echo base_url(); ?&gt;shiprocket/shiprocketSendToCustomer" method="post"&gt;
		&lt;button type="submit" alue="Submit"&gt;Send to Customer&lt;/button&gt;
	&lt;/form&gt;
	
	&lt;form action="&lt;?php echo base_url(); ?&gt;shiprocket/shiprocketPickupFromCustomer" method="post"&gt;
		&lt;button type="submit" alue="Submit"&gt;Pickup From Customer&lt;/button&gt;
	&lt;/form&gt;
&lt;/div&gt;


&lt;/body&gt;
&lt;/html&gt;</pre><p>&nbsp;</p>
<p><a href="https://github.com/vipulrai/Shiprocket-API-for-PHP-CodeIgniter" target="_blank" rel="noopener"><span style="color: #008000;"><strong>DOWNLOAD</strong></span></a></p>
<p>&nbsp;</p>
<p>The post <a href="https://www.codypaste.com/shiprocket-api-in-php-codeigniter/">Shiprocket API in PHP CodeIgniter</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/shiprocket-api-in-php-codeigniter/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
