shiprocket

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 19 Imported by: 0

README

shiprocket-gosdk

Unofficial Shiprocket Go SDK with typed services for the public Shiprocket API surface documented on July 23, 2026.

  • Docs source audited against https://apidocs.shiprocket.in/ and Shiprocket's published Postman collection on July 23, 2026.
  • Minimum supported Go version: 1.22
  • Release posture: pre-v1, compatibility policy documented in RELEASING.md

Installation

go get github.com/Niyantra-Labs/shiprocket-gosdk

Quickstart

package main

import (
	"context"
	"fmt"
	"log"

	shiprocket "github.com/Niyantra-Labs/shiprocket-gosdk"
	"github.com/Niyantra-Labs/shiprocket-gosdk/orders"
)

func main() {
	ctx := context.Background()

	client := shiprocket.NewClient(shiprocket.Config{
		Credentials: &shiprocket.Credentials{
			Email:    "ops@example.com",
			Password: "shiprocket-password",
		},
	})

	resp, err := client.Orders.CreateCustomOrder(ctx, &orders.CreateCustomOrderRequest{
		OrderRequestFields: orders.OrderRequestFields{
			ReferenceOrderID:    "ref-1001",
			OrderDate:           "2026-07-23 10:00",
			PickupLocation:      "Primary Warehouse",
			BillingCustomerName: "Jane Customer",
			BillingAddress:      "Street 1",
			BillingCity:         "Delhi",
			BillingPincode:      "110001",
			BillingState:        "Delhi",
			BillingCountry:      "India",
			BillingEmail:        "jane@example.com",
			BillingPhone:        "9999999999",
			PaymentMethod:       "Prepaid",
			OrderItems: []orders.OrderItem{
				{Name: "Widget", Sku: "W-1", Units: 1, SellingPrice: "499"},
			},
			SubTotal: 499,
			Length:   10,
			Breadth:  10,
			Height:   10,
			Weight:   0.5,
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(resp.ShiprocketOrderID)
}

Status

Core services are available through the root client:

  • client.Auth
  • client.Orders
  • client.Couriers
  • client.PickupAddresses
  • client.Products
  • client.Listings
  • client.Channels
  • client.Inventory
  • client.Location
  • client.International
  • client.Hyperlocal
  • client.Account
  • client.Returns
  • client.Shipments
  • client.NDR

Compatibility wrappers remain available for older integrations, but new code should prefer the root client.

Coverage

Module Status Notes
Authentication Complete Login, logout, credential-backed token lifecycle
Orders Complete Custom, channel, update, cancel, fulfill, map, import, list, detail, export
Courier and Pickup Complete Serviceability, courier list, AWB, pickup, blocked pincodes, pickup addresses
Shipments and Tracking Complete List, detail, cancel, labels, manifests, invoice, tracking variants
Returns and NDR Complete Returns, exchanges, updates, return serviceability/AWB, NDR list/detail/action
Catalog and Inventory Complete Products, listings, channels, inventory
International and Hyperlocal Complete Dedicated international endpoints plus documented aliases and hyperlocal wrapper layer
Account and Billing Complete Wallet balance, statement, discrepancy, import result checks

Detailed path-to-method mapping lives in docs/reference/coverage.md.

Docs

Examples

Runnable example programs live under docs/examples. Each one can be executed with go run ./docs/examples/<name> after setting the documented environment variables.

Testing and CI

  • go test ./...
  • go test -race ./...
  • go test -coverprofile=coverage.out ./...
  • golangci-lint run

GitHub Actions definitions live in .github/workflows/ci.yml and .github/workflows/live-smoke.yml.

Documentation

Index

Examples

Constants

View Source
const DefaultBaseURL = internalclient.DefaultBaseURL

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError = internalclient.APIError

type AuthError

type AuthError = internalclient.AuthError

type BusinessError

type BusinessError = internalclient.BusinessError

type Client

type Client struct {
	Config Config

	Auth            *auth.Service
	Orders          *orders.Service
	Couriers        *courier.Service
	PickupAddresses *pickupaddress.Service
	Products        *products.Service
	Listings        *listings.Service
	Channels        *channels.Service
	Inventory       *inventory.Service
	Location        *location.Service
	International   *international.Service
	Hyperlocal      *hyperlocal.Service
	Account         *account.Service
	Returns         *returns.Service
	Shipments       *shipment.Service
	NDR             *ndr.Service
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg Config) *Client
Example
package main

import (
	"context"
	"net/http"
	"time"

	shiprocket "github.com/Niyantra-Labs/shiprocket-gosdk"
	"github.com/Niyantra-Labs/shiprocket-gosdk/account"
	"github.com/Niyantra-Labs/shiprocket-gosdk/channels"
	"github.com/Niyantra-Labs/shiprocket-gosdk/courier"
	"github.com/Niyantra-Labs/shiprocket-gosdk/international"
	"github.com/Niyantra-Labs/shiprocket-gosdk/inventory"
	"github.com/Niyantra-Labs/shiprocket-gosdk/listings"
	"github.com/Niyantra-Labs/shiprocket-gosdk/location"
	"github.com/Niyantra-Labs/shiprocket-gosdk/ndr"
	"github.com/Niyantra-Labs/shiprocket-gosdk/orders"
	"github.com/Niyantra-Labs/shiprocket-gosdk/products"
	"github.com/Niyantra-Labs/shiprocket-gosdk/returns"
	"github.com/Niyantra-Labs/shiprocket-gosdk/shipment"
)

func main() {
	client := shiprocket.NewClient(shiprocket.Config{
		Token: "your-token",
		HTTPClient: &http.Client{
			Timeout: 30 * time.Second,
		},
		UserAgent: "example-app/1.0",
	})

	_, _ = client.Orders.CreateCustomOrder(context.Background(), &orders.CreateCustomOrderRequest{
		OrderRequestFields: orders.OrderRequestFields{
			ReferenceOrderID:    "ref-1001",
			OrderDate:           "2026-07-23 10:00",
			PickupLocation:      "Primary Warehouse",
			BillingCustomerName: "Jane",
			BillingAddress:      "Street 1",
			BillingCity:         "Delhi",
			BillingPincode:      "110001",
			BillingState:        "Delhi",
			BillingCountry:      "India",
			BillingEmail:        "jane@example.com",
			BillingPhone:        "9999999999",
			OrderItems: []orders.OrderItem{
				{Name: "Widget", Sku: "W-1", Units: 1, SellingPrice: "499"},
			},
			PaymentMethod: "Prepaid",
			SubTotal:      499,
			Length:        10,
			Breadth:       10,
			Height:        10,
			Weight:        0.5,
		},
	})

	label, _ := client.Shipments.GenerateLabel(context.Background(), &shipment.GenerateLabelRequest{
		ShipmentID: []int64{16104408},
	})
	if label != nil {
		_, _ = client.Shipments.DownloadArtifact(context.Background(), label.LabelURL)
	}

	_, _ = client.Returns.CreateReturnOrder(context.Background(), &returns.CreateReturnOrderRequest{
		OrderID:              "R-1001",
		OrderDate:            "2026-07-23",
		PickupCustomerName:   "Jane",
		PickupAddress:        "Customer Street 1",
		PickupCity:           "Delhi",
		PickupState:          "Delhi",
		PickupCountry:        "India",
		PickupPincode:        "110001",
		PickupEmail:          "jane@example.com",
		PickupPhone:          "9999999999",
		ShippingCustomerName: "Warehouse",
		ShippingAddress:      "Return Hub",
		ShippingCity:         "Delhi",
		ShippingCountry:      "India",
		ShippingPincode:      "110002",
		ShippingState:        "Delhi",
		ShippingPhone:        "8888888888",
		OrderItems: []returns.ReturnOrderItem{
			{Name: "Widget", SKU: "W-1", Units: 1, SellingPrice: "499"},
		},
		PaymentMethod: "PREPAID",
		SubTotal:      499,
		Length:        10,
		Breadth:       10,
		Height:        10,
		Weight:        0.5,
	})

	_, _ = client.NDR.Act(context.Background(), &ndr.ActionRequest{
		AWB:      "8373927474982",
		Action:   ndr.ActionReturn,
		Comments: "Customer refused delivery",
	})

	_, _ = client.Products.Create(context.Background(), &products.CreateRequest{
		Name:         "Batman451",
		CategoryCode: "default",
		Type:         "Single",
		Qty:          "10",
		SKU:          "b118771212",
	})

	_, _ = client.Listings.Link(context.Background(), &listings.LinkRequest{
		ProductID: "17484610",
		ListingID: "15897064",
		ID:        "manual-map-1",
	})

	_, _ = client.Channels.Create(context.Background(), &channels.CreateRequest{
		Name:      "MANUAL-25149",
		BrandName: "SIORA-12",
	})

	_, _ = client.Inventory.Update(context.Background(), &inventory.UpdateRequest{
		ProductID: "3448631",
		Payload: &inventory.UpdatePayload{
			Quantity: "51",
			Action:   "set",
		},
	})

	_, _ = client.Location.GetPostcodeDetails(context.Background(), &location.PostcodeDetailsRequest{
		Postcode: "110077",
	})

	_, _ = client.Account.GetStatement(context.Background(), &account.StatementParams{
		Page:    1,
		PerPage: 20,
	})

	_, _ = client.International.CheckServiceability(context.Background(), &international.ServiceabilityParams{
		Weight:          "10",
		COD:             0,
		DeliveryCountry: "US",
	})

	_, _ = client.Hyperlocal.CheckServiceability(context.Background(), &courier.ServiceabilityParams{
		PickupPostcode:   "110001",
		DeliveryPostcode: "560034",
	})
}

func (*Client) BaseURL

func (c *Client) BaseURL() string

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *Request, out any) error

func (*Client) DoBytes

func (c *Client) DoBytes(ctx context.Context, req *Request) ([]byte, error)

func (*Client) DoDownload

func (c *Client) DoDownload(ctx context.Context, req *Request) (*Download, error)

func (*Client) DoRaw

func (c *Client) DoRaw(ctx context.Context, req *Request) (*http.Response, error)

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

type Config

type Config struct {
	BaseURL     string
	Token       string
	TokenSource TokenSource
	Credentials *Credentials
	HTTPClient  *http.Client
	Timeout     time.Duration
	UserAgent   string
	Logger      Logger
	Hooks       []Hook
	Middleware  []Middleware
}

type Credentials

type Credentials struct {
	Email    string
	Password string
}

type Download

type Download = internalclient.Download

type Hook

type Hook = internalclient.Hook

type Logger

type Logger = internalclient.Logger

type LoginRequest

type LoginRequest = auth.LoginRequest

type LoginResponse

type LoginResponse = auth.LoginResponse

type Middleware

type Middleware = internalclient.Middleware

type MultipartBody

type MultipartBody = internalclient.MultipartBody

type MultipartFile

type MultipartFile = internalclient.MultipartFile

type RateLimitError

type RateLimitError = internalclient.RateLimitError

type Request

type Request = internalclient.Request

type ResponseMeta

type ResponseMeta = internalclient.ResponseMeta

type ServerError

type ServerError = internalclient.ServerError

type StaticTokenSource

type StaticTokenSource struct {
	TokenValue string
}

func (StaticTokenSource) Token

type TokenSource

type TokenSource = internalclient.TokenSource

type TransportError

type TransportError = internalclient.TransportError

type ValidationError

type ValidationError = internalclient.ValidationError

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL