Shiprocket API Wrapper for Laravel
- Up-to-date with Shiprocket's API
- Fully Customizeable
- Easy One Liners
- Token Caching
- Any Data Type for Response
You can install the package via composer:
composer require aniket-in/shiprocket-laravel
You can publish config file with:
php artisan vendor:publish --provider="AniketIN\Shiprocket\ShiprocketServiceProvider" --tag="shiprocket-config"
This is the contents of the published config file:
return [
/*
|--------------------------------------------------------------------------
| Shiprocket Credentilas
|--------------------------------------------------------------------------
|
| Here you can set multiple shiprocket credentilas pair.
| And then use any credential pair by their key i.e. default, second
|
*/
'credentials' => [
'default' => [
'email' => env('SHIPROCKET_EMAIL', 'example@email.com'),
'password' => env('SHIPROCKET_PASSWORD', 'password'),
],
// 'second' => [
// 'email' => env('SHIPROCKET_SECOND_EMAIL', 'example@email.com'),
// 'password' => env('SHIPROCKET_SECOND_PASSWORD', 'password'),
// ],
],
/*
|--------------------------------------------------------------------------
| Shiprocket Credentilas
|--------------------------------------------------------------------------
|
| Here you can set the default credentilas to use by their key.
| i.e. default, second
|
*/
'default_credentials' => env('SHIPROCKET_DEFAULT_CREDENTIALS', 'default'),
/*
|--------------------------------------------------------------------------
| Shiprocket Credentilas
|--------------------------------------------------------------------------
|
| Here you can set the behaviour whether to use caching or not for auth tokens.
|
*/
'token_cache' => env('SHIPROCKET_TOKEN_CACHE', true),
/*
|--------------------------------------------------------------------------
| Token Cache Expiry Duration
|--------------------------------------------------------------------------
|
| Here you can set token's cache expiry duration
|
*/
'token_cache_duration' => env('SHIPROCKET_TOKEN_CACHE_DURATION', 86400),
];
To use the methods of this package, import the Facade on top of your controller like this:
use AniketIN\Shiprocket\Facades\Shiprocket;
Using this package handle the Authentication itself, you don't need to do anything other than, just setting up your Shiprocket credentials in the config/shiprocket.php
file.
You can also configure token caching to true
in that config file.
This will save a lot of time by caching the token and not generating new token on every request.
The cache duration
is also customizeable.
However, if you want to just get the token
Shiprocket::getToken();
Also, if you want to use different credential other than the default one, then:
Shiprocket::withCredential('another-credential-key')->nowCallYourMethod(...);
To get the returned response from the API, you may use any of the Laravel provided method, like:
Shiprocket::order()->all()->json();
All available methods:
$response->body() : string;
$response->json($key = null) : array|mixed;
$response->object() : object;
$response->collect($key = null) : Illuminate\Support\Collection;
$response->status() : int;
$response->ok() : bool;
$response->successful() : bool;
$response->redirect(): bool;
$response->failed() : bool;
$response->serverError() : bool;
$response->clientError() : bool;
$response->header($header) : string;
$response->headers() : array;
For more information refer https://laravel.com/docs/9.x/http-client#making-requests
https://apidocs.shiprocket.in/#247e58f3-37f3-4dfb-a4bb-b8f6ab6d41ec
Shiprocket::order()->create([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#45126d19-74ed-4cf5-9447-8ac1041bbb3c
Shiprocket::order()->createChannelSpecific([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#4ba045ab-e25b-4bb1-adbd-37bbd07b354e
Shiprocket::order()->updatePickupAddress([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#f98ea72a-2efb-4bbc-a4bb-f4dd7e15618a
Shiprocket::order()->updateCustomerAddress([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#f08900fe-ea38-485d-b50c-3ec2fbc5644a
Shiprocket::order()->update([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#5c0e41ca-d868-44c4-8ddb-73a8de239401
Shiprocket::order()->cancelByIds([
// order ids...
])
https://apidocs.shiprocket.in/#d4f48023-b0b2-40af-8072-1adf97227d21
Shiprocket::order()->all([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#aa23cc40-6ee8-4ce0-b0ab-1a7291514299
Shiprocket::order()->detailsById($orderId)
https://apidocs.shiprocket.in/#b267ca9a-f7aa-4edc-8477-7dc15e46e08a
Shiprocket::courier()->generateAwbForShipment([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#ce08883d-5782-4523-a425-919d10b27536
Shiprocket::courier()->list([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#29ff5116-0917-41ba-8c82-638412604916
Shiprocket::courier()->serviceability([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#6d1f2fb0-43c1-434f-8c93-50674a0b59ef
Shiprocket::courier()->internationalServiceability([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#9f42cdfd-a055-4934-a0f4-86764f87c80d
Shiprocket::courier()->requestShipmentPickup([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#81b2135b-d43c-4002-8f7f-a670aa5210fa
Shiprocket::return()->create([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#a98c37b1-47ac-40b4-b80f-051611fe350e
Shiprocket::return()->all([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#a9913eaf-94ba-4012-a105-9687fddc7221
Shiprocket::shipment()->all([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#5f9bced5-4f16-4868-be55-a8c0215d0711
Shiprocket::shipment()->detailsById($shipment_id)
https://apidocs.shiprocket.in/#659bb564-413a-4e4c-b866-ebe01d3f61dc
Shiprocket::shipment()->cancelByAWBs([123456, 7890123])
https://apidocs.shiprocket.in/#f2ac0962-4c34-4fe4-8266-50f8a1e8eab0
Shiprocket::track()->awb($awb)
https://apidocs.shiprocket.in/#cf273e6a-08d0-4624-bf7a-7510c28292e0
Shiprocket::track()->multipleAwb($awb_array)
https://apidocs.shiprocket.in/#89005f4f-2b2f-473d-95b0-f54665a16b42
Shiprocket::track()->shipment($shipment_id)
https://apidocs.shiprocket.in/#bfcf3357-4e39-4134-831a-1ff33f67205e
Shiprocket::track()->order($order_id)
https://apidocs.shiprocket.in/#3bd67de6-8f00-435f-a708-c0c3ab252fee
Shiprocket::pickupAddress()->all()
https://apidocs.shiprocket.in/#6fbe81f5-c3d5-462e-b18f-d6316dde7779
Shiprocket::pickupAddress()->create([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#341bd458-5d80-4978-8e30-13651be2a652
Shiprocket::wallet()->getBalance()
https://apidocs.shiprocket.in/#0b8d1f26-3abd-4f4e-9cd8-3928bcfcf30b
Shiprocket::product()->all([
// refer above url for required parameters...
])
https://apidocs.shiprocket.in/#134f7710-660c-464f-b579-6da46ba9402f
Shiprocket::product()->detailsById($product_id)
https://apidocs.shiprocket.in/#344b789d-584e-486a-a7a9-0cf33ce52bf3
Shiprocket::product()->create([
// refer above url for required parameters...
])
For support or feedback, email laravel-shiprocket@aniket.ind.in or raise your issue.