klikresi

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 10 Imported by: 0

README

Klik Resi Go SDK

Official Go client for the Klik Resi API. Track shipments, calculate shipping rates, and look up Indonesian locations (provinces, cities, districts) across couriers such as JNE, J&T, Shopee Express, SiCepat, TIKI, and more.

Full API reference: docs.klikresi.com

Requirements

  • Go 1.24+

Installation

go get github.com/klikresi/go-sdk

Quickstart

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/klikresi/go-sdk"
)

func main() {
	client := klikresi.NewClient("YOUR-API-KEY")
	ctx := context.Background()

	tracking, err := client.Tracking.Get(ctx, "YOUR-AWB", klikresi.CourierJNE)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(tracking.Status)
	for _, h := range tracking.Histories {
		fmt.Println(h.Date, h.Message)
	}
}

Usage

Tracking
// Basic tracking (charged per successful request).
t, err := client.Tracking.Get(ctx, "YOUR-AWB", klikresi.CourierJNE)

// ID Express requires an extra `number` (phone number) parameter.
// When provided, it is passed through as a query parameter.
t, err := client.Tracking.Get(ctx, "YOUR-AWB", klikresi.CourierIDExpress, klikresi.WithNumber("08123456789"))

The response contains a normalized DeliveryStatus (InfoReceived, InTransit, OutForDelivery, FailedAttempt, Delivered, ReturnToSender, Exception, Expired, Pending) plus origin, destination, and the full event history.

Rates
// By district IDs, optionally filtered to specific couriers.
r, err := client.Rates.CalculateByID(ctx, "33.08.20", "32.09.31", 1, klikresi.CourierJNE)

// By location names.
r, err := client.Rates.CalculateByName(ctx, "Secang, Kabupaten Magelang, Jawa Tengah", "Depok, Kabupaten Cirebon, Jawa Barat", 1)

// By postal codes.
r, err := client.Rates.CalculateByPostalCode(ctx, 56195, 45155, 1)
Location

All location endpoints are cursor-paginated. Request one page, or use the All* helpers to fetch everything automatically.

// Search locations by keyword.
page, err := client.Location.Search(ctx, "depok", klikresi.WithLimit(10))

// Single pages.
provinces, err := client.Location.Provinces(ctx)
cities, err    := client.Location.Cities(ctx, "33")
districts, err := client.Location.Districts(ctx, "33.08")

// Everything, following cursors automatically.
all, err := client.Location.AllLocations(ctx, "depok")
allProvinces, err := client.Location.AllProvinces(ctx)
Me
// Fetch the profile of the account that owns the API key.
me, err := client.Me.Get(ctx)

The response contains the account ID, Name, Email, and current Balance.

Courier codes

Use the exported constants: klikresi.CourierSPX, klikresi.CourierJNE, klikresi.CourierJNT, klikresi.CourierSicepat, klikresi.CourierNinja, klikresi.CourierPos, klikresi.CourierSAP, klikresi.CourierLEX, klikresi.CourierLion, klikresi.CourierIDExpress, klikresi.CourierAnteraja, klikresi.CourierWahana, klikresi.CourierTiki.

Errors

Any non-2xx response returns an *klikresi.APIError implementing error, with the HTTP StatusCode and the API's Message:

var apiErr *klikresi.APIError
if errors.As(err, &apiErr) {
	fmt.Println(apiErr.StatusCode, apiErr.Message)
}

Configuration

The client constructor takes only your API key. The base URL defaults to https://klikresi.com; it can be overridden with the KLIKRESI_BASE_URL environment variable (useful for tests and proxies). Every request is bound to the context.Context you pass and times out after 30 seconds.

Examples

See the examples directory for runnable samples (KLIKRESI_API_KEY=... go run ./examples/tracking).

License

MIT

Documentation

Overview

Package klikresi provides a client for the Klik Resi API.

It supports account lookup, shipment tracking, shipping rate calculation, and location lookup (search, provinces, cities, districts) across Indonesian couriers.

Create a client with NewClient and use the resources grouped under Tracking, Rates, Location, and Me:

client := klikresi.NewClient("your-api-key")
tracking, err := client.Tracking.Get(ctx, "YOUR-AWB", klikresi.CourierJNE)

Index

Constants

View Source
const (
	// CourierSPX is Shopee Express.
	CourierSPX = "spx"
	// CourierJNE is Jalur Nugraha Ekakurir.
	CourierJNE = "jne"
	// CourierJNT is J&T Express.
	CourierJNT = "jnt"
	// CourierSicepat is Sicepat Express.
	CourierSicepat = "sicepat"
	// CourierNinja is Ninja Express.
	CourierNinja = "ninja"
	// CourierPos is POS Indonesia.
	CourierPos = "pos"
	// CourierSAP is SAP Express.
	CourierSAP = "sap"
	// CourierLEX is Lazada Logistics.
	CourierLEX = "lex"
	// CourierLion is Lion Parcel.
	CourierLion = "lion"
	// CourierIDExpress is ID Express.
	CourierIDExpress = "ide"
	// CourierAnteraja is Anteraja.
	CourierAnteraja = "anteraja"
	// CourierWahana is Wahana Prestasi Logistik.
	CourierWahana = "wahana"
	// CourierTiki is TIKI.
	CourierTiki = "tiki"
)

Supported courier codes. Use these with Tracking.Get and the Rates courier filter instead of hard-coding strings.

View Source
const (
	// DefaultBaseURL is the production API endpoint.
	DefaultBaseURL = "https://klikresi.com"

	// BaseURLEnv overrides DefaultBaseURL when set. It is mainly useful
	// for tests and proxies.
	BaseURLEnv = "KLIKRESI_BASE_URL"

	// DefaultTimeout is applied to every request when the client is
	// created with NewClient.
	DefaultTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// StatusCode is the HTTP status code returned by the API.
	StatusCode int
	// Message is the error message returned by the API, when available.
	Message string
}

APIError is returned for any non-2xx API response.

func (*APIError) Error

func (e *APIError) Error() string

type AccountProfile added in v1.1.0

type AccountProfile struct {
	ID      string  `json:"id"`
	Name    string  `json:"name"`
	Email   string  `json:"email"`
	Balance float64 `json:"balance"`
}

AccountProfile is the profile of the account that owns the API key.

type Address

type Address struct {
	ContactName string `json:"contact_name"`
	Address     string `json:"address"`
}

Address identifies a sender or a recipient.

type City

type City struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

City is an Indonesian city or regency.

type CityPage

type CityPage struct {
	Data       []City `json:"data"`
	NextCursor string `json:"next_cursor"`
}

CityPage is one page of cities.

type Client

type Client struct {

	// Tracking provides access to the tracking API.
	Tracking *Tracking
	// Rates provides access to the rates API.
	Rates *Rates
	// Location provides access to the location API.
	Location *Location
	// Me provides access to the account profile API.
	Me *Me
	// contains filtered or unexported fields
}

Client is a Klik Resi API client. It is safe for concurrent use.

func NewClient

func NewClient(apiKey string) *Client

NewClient returns a Client for the given API key. The base URL defaults to https://klikresi.com and can be overridden with the KLIKRESI_BASE_URL environment variable.

type DeliveryStatus

type DeliveryStatus string

DeliveryStatus is the normalized shipment status returned by the tracking API.

const (
	// StatusInfoReceived means the carrier has received the package info
	// and is about to pick up the package.
	StatusInfoReceived DeliveryStatus = "InfoReceived"
	// StatusInTransit means the package is in transit and has a good
	// transportation condition.
	StatusInTransit DeliveryStatus = "InTransit"
	// StatusOutForDelivery means the package has arrived at the local
	// point or is on the way to the recipient.
	StatusOutForDelivery DeliveryStatus = "OutForDelivery"
	// StatusFailedAttempt means the delivery of the package was attempted
	// but failed due to some reasons.
	StatusFailedAttempt DeliveryStatus = "FailedAttempt"
	// StatusDelivered means the package has been delivered.
	StatusDelivered DeliveryStatus = "Delivered"
	// StatusReturnToSender means the package is on the way back to the
	// sender.
	StatusReturnToSender DeliveryStatus = "ReturnToSender"
	// StatusException means the package was lost, damaged, on hold, etc.
	StatusException DeliveryStatus = "Exception"
	// StatusExpired means the last track of the package has not been
	// updated for 30 days.
	StatusExpired DeliveryStatus = "Expired"
	// StatusPending means no information yet as the package is pending to
	// track or the carrier is wrong.
	StatusPending DeliveryStatus = "Pending"
)

Delivery statuses returned by the tracking API.

type District

type District struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

District is an Indonesian district.

type DistrictPage

type DistrictPage struct {
	Data       []District `json:"data"`
	NextCursor string     `json:"next_cursor"`
}

DistrictPage is one page of districts.

type History

type History struct {
	Status  DeliveryStatus `json:"status"`
	Message string         `json:"message"`
	Date    time.Time      `json:"date"`
}

History is a single tracking event.

type Location

type Location struct {
	// contains filtered or unexported fields
}

Location provides access to the location API.

func (*Location) AllCities

func (l *Location) AllCities(ctx context.Context, provinceID string, opts ...PageOption) ([]City, error)

AllCities returns every city within the given province, following pagination cursors automatically.

func (*Location) AllDistricts

func (l *Location) AllDistricts(ctx context.Context, cityID string, opts ...PageOption) ([]District, error)

AllDistricts returns every district within the given city, following pagination cursors automatically.

func (*Location) AllLocations

func (l *Location) AllLocations(ctx context.Context, keyword string, opts ...PageOption) ([]LocationInfo, error)

AllLocations returns every location matching the keyword, following pagination cursors automatically.

func (*Location) AllProvinces

func (l *Location) AllProvinces(ctx context.Context, opts ...PageOption) ([]Province, error)

AllProvinces returns every province, following pagination cursors automatically.

func (*Location) Cities

func (l *Location) Cities(ctx context.Context, provinceID string, opts ...PageOption) (*CityPage, error)

Cities returns one page of cities within the given province.

func (*Location) Districts

func (l *Location) Districts(ctx context.Context, cityID string, opts ...PageOption) (*DistrictPage, error)

Districts returns one page of districts within the given city.

func (*Location) Provinces

func (l *Location) Provinces(ctx context.Context, opts ...PageOption) (*ProvincePage, error)

Provinces returns one page of provinces.

func (*Location) Search

func (l *Location) Search(ctx context.Context, keyword string, opts ...PageOption) (*LocationPage, error)

Search looks up locations matching the given keyword.

type LocationInfo

type LocationInfo struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	District string `json:"district"`
	City     string `json:"city"`
	Province string `json:"province"`
}

LocationInfo is a district-level location returned by the location search.

type LocationPage

type LocationPage struct {
	Data       []LocationInfo `json:"data"`
	NextCursor string         `json:"next_cursor"`
}

LocationPage is one page of location search results.

type LocationRef

type LocationRef struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

LocationRef identifies a location by id and name.

type Me added in v1.1.0

type Me struct {
	// contains filtered or unexported fields
}

Me provides access to the account profile API.

func (*Me) Get added in v1.1.0

func (m *Me) Get(ctx context.Context) (*AccountProfile, error)

Get returns the profile of the account that owns the API key.

type PageOption

type PageOption func(*pageOptions)

PageOption configures a paginated location request.

func WithCursor

func WithCursor(cursor string) PageOption

WithCursor sets the pagination cursor returned by the previous page.

func WithLimit

func WithLimit(limit int) PageOption

WithLimit sets the number of items per page. The API default is 50.

type Pricing

type Pricing struct {
	Type        string  `json:"type"`
	CourierCode string  `json:"courier_code"`
	CourierName string  `json:"courier_name"`
	Service     string  `json:"service"`
	Price       float64 `json:"price"`
	Duration    string  `json:"duration"`
}

Pricing is a single shipping rate offer from a courier.

type Province

type Province struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Province is an Indonesian province.

type ProvincePage

type ProvincePage struct {
	Data       []Province `json:"data"`
	NextCursor string     `json:"next_cursor"`
}

ProvincePage is one page of provinces.

type RateResult

type RateResult struct {
	Origin      LocationRef `json:"origin"`
	Destination LocationRef `json:"destination"`
	Pricing     []Pricing   `json:"pricing"`
}

RateResult contains shipping rates between an origin and a destination.

type Rates

type Rates struct {
	// contains filtered or unexported fields
}

Rates provides access to the rates API.

func (*Rates) CalculateByID

func (r *Rates) CalculateByID(ctx context.Context, originID, destinationID string, weight float64, couriers ...string) (*RateResult, error)

CalculateByID calculates shipping rates using district IDs as the origin and destination. Couriers optionally filters the result to the given courier codes.

func (*Rates) CalculateByName

func (r *Rates) CalculateByName(ctx context.Context, origin, destination string, weight float64) (*RateResult, error)

CalculateByName calculates shipping rates using location names as the origin and destination.

func (*Rates) CalculateByPostalCode

func (r *Rates) CalculateByPostalCode(ctx context.Context, originPostalCode, destinationPostalCode int, weight float64) (*RateResult, error)

CalculateByPostalCode calculates shipping rates using postal codes as the origin and destination.

type Tracking

type Tracking struct {
	// contains filtered or unexported fields
}

Tracking provides access to the tracking API.

func (*Tracking) Get

func (t *Tracking) Get(ctx context.Context, trackingNumber, courierCode string, opts ...TrackingOption) (*TrackingInfo, error)

Get returns the tracking information for the given tracking number and courier code. Tracking is charged only for successful requests.

type TrackingInfo

type TrackingInfo struct {
	// Status is the normalized delivery status.
	Status DeliveryStatus `json:"status"`
	// Origin is the sender address.
	Origin Address `json:"origin"`
	// Destination is the recipient address.
	Destination Address `json:"destination"`
	// Histories lists the tracking events, newest first.
	Histories []History `json:"histories"`
}

TrackingInfo is the full tracking information for a shipment.

type TrackingOption

type TrackingOption func(*trackingOptions)

TrackingOption configures a tracking request.

func WithNumber

func WithNumber(number string) TrackingOption

WithNumber adds the `number` query parameter. It is required by ID Express (courier "ide") and is passed through for every courier whenever it is provided.

Directories

Path Synopsis
examples
location command
me command
rates command
tracking command

Jump to

Keyboard shortcuts

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