Shipper API Go Client
Unofficial library for access Shipper API from applications written with Go.
Installation
Install shipper-go using Go Module by following command:
go get github.com/denifrahman/shipper-go
Then you import it by following code:
import "github.com/denifrahman/shipper-go"
Usage
Set the API Key
Configure package with your account's API key obtained from Shipper.
shipper.Conf.SetAPIKey("API_KEY")
Set the Production Mode
When deploying your application to production, you may want to change API Endpoint as well by setting SetProductionMode
to true
.
shipper.Conf.SetProductionMode(true)
// or chain it with SetAPIKey method
shipper.Conf.SetAPIKey("API_KEY").SetProductionMode(true)
Available Methods and Examples
Locations
You need to import location
package first by following code:
import "github.com/denifrahman/shipper-go/location"
Get Countries
Retrieve country data in a list.
func GetCountries()
Usage example:
var countries, err = location.GetCountries()
if err != nil {
panic(err.Error())
}
fmt.Printf("List Countries: %+v\n", countries)
Get Provinces
Retrieve all provinces in Indonesia in a list.
func GetProvinces()
Usage example:
var provinces, err = location.GetProvinces()
if err != nil {
panic(err.Error())
}
fmt.Printf("List Provinces: %+v\n", provinces)
Get Cities
Retrieve cities based on submitted province ID.
func GetCities(provinceID int)
Usage example:
var cities, err = location.GetCities(9)
if err != nil {
panic(err.Error())
}
fmt.Printf("List Cities: %+v\n", cities)
Get Origin Cities
Retrieve provinces in which Shipper provides pickup service.
func GetOriginCities()
Usage example:
var originCities, err = location.GetOriginCities()
if err != nil {
panic(err.Error())
}
fmt.Printf("List Origin Cities: %+v\n", originCities)
Get Suburbs
Retrieve suburbs based on submitted city ID.
func GetSuburbs(cityID int)
Usage example:
var suburbs, err = location.GetSuburbs(80)
if err != nil {
panic(err.Error())
}
fmt.Printf("List Suburbs: %+v\n", suburbs)
Get Areas
Retrieve areas based on submitted suburb ID.
func GetAreas(suburbID int)
Usage example:
var areas, err = location.GetAreas(1330)
if err != nil {
panic(err.Error())
}
fmt.Printf("List Areas: %+v\n", areas)
Search Location
Retrieve every area, suburb, and city whose names include the submitted substring (including postcode).
func GetAreas(substring string)
Usage example:
var searchLocation, err = location.SearchLocation("Sukmajaya")
if err != nil {
panic(err.Error())
}
fmt.Printf("Searched Location: %+v\n", searchLocation)
Rates
You need to import rates
package first by following code:
import "github.com/denifrahman/shipper-go/rates"
Get Domestic Rates
func GetDomesticRates(params *DomesticRatesParams)
Usage example:
var domesticRates, err = rates.GetDomesticRates(&rates.DomesticRatesParams{
Origin: 12921,
Destination: 4645,
Length: 10,
Width: 10,
Height: 10,
WeightTotal: 0.4,
Value: 70000,
Type: 1,
COD: 1,
Order: 0,
OriginCoordinate: "-6.308033944807303,106.73339847804874",
DestinationCoordinate: "49.020733179213,12.114381752908",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("Domestic Rates: %+v\n", domesticRates)
Get International Rates
func GetInternationalRates(params *InternationalRatesParams)
Usage example:
var internationalRates, err = rates.GetInternationalRates(&rates.InternationalRatesParams{
Origin: 4819,
Destination: 12,
Length: 10,
Width: 10,
Height: 10,
WeightTotal: 0.4,
Value: 150000,
Type: 2,
Order: 0,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("International Rates: %+v\n", internationalRates)
Orders
You need to import order
package first by following code:
import "github.com/denifrahman/shipper-go/order"
Create Domestic Order
func CreateDomesticOrder(params *DomesticOrderParams)
Usage example:
var domesticOrder, err = order.CreateDomesticOrder(&order.DomesticOrderParams{
Origin: 12921,
Destination: 4645,
Length: 10,
Width: 10,
Height: 10,
WeightTotal: 0.4,
Value: 100000,
RateID: 59,
ConsigneeName: "Peoorang",
ConsigneePhoneNumber: "089899878987",
ConsignerName: "Peorang",
ConsignerPhoneNumber: "089891891818",
OriginAddress: "Mangga Dua Selatan",
OriginDirection: "Just follow the road",
DestinationAddress: "Pasar Baru",
DestinationDirection: "Lurus terus",
ItemName: []ItemName{
{
Name: "Baju",
Qty: 1,
Value: 100000,
},
},
Contents: "Barang mudah pecah",
UseInsurance: 0,
ExternalID: "",
PaymentType: "cash",
PackageType: 1,
COD: 0,
OriginCoordinate: "-6.308033944807303,106.73339847804874",
DestinationCoordinate: "49.020733179213,12.114381752908",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("Domestic Order: %+v\n", domesticOrder)
Create International Order
func CreateInternationalOrder(params *InternationalOrderParams)
Usage example:
var internationalOrder, err = order.CreateInternationalOrder(&order.InternationalOrderParams{
Origin: 4819,
Destination: 12,
Length: 10,
Width: 10,
Height: 10,
WeightTotal: 0.4,
Value: 150000,
RateID: 327,
ConsigneeName: "Peoorang",
ConsigneePhoneNumber: "089899878987",
ConsignerName: "Peorang",
ConsignerPhoneNumber: "089891891818",
OriginAddress: "Mangga Dua Selatan",
OriginDirection: "Just follow the road",
DestinationAddress: "Orchard Road 101",
DestinationDirection: "Lurus terus",
DestinationArea: "Singapore",
DestinationSuburb: "Singapore",
DestinationCity: "Singapore",
DestinationProvince: "Singapore",
DestinationPostCode: "111111",
ItemName: []ItemName{
{
Name: "Baju",
Qty: 1,
Value: 150000,
},
},
Contents: "Barang mudah pecah",
UseInsurance: 0,
PackageType: 2,
PaymentType: "cash",
ExternalID: ""
})
if err != nil {
panic(err.Error())
}
fmt.Printf("International Order: %+v\n", internationalOrder)
Get Tracking ID
Retrieve tracking ID of the order with the provided ID.
func GetTrackingID(orderID string)
Usage example:
var trackingID, err = order.GetTrackingID("5f259130a172cf001222f533")
if err != nil {
panic(err.Error())
}
fmt.Printf("Tracking ID: %+v\n", trackingID)
Activate Order
Activate/Deactivate an order. Such activation will initiate Shipper's pickup process.
func ActivateOrder(orderID string, params *ActivateParams)
Usage example:
var activatedOrder, err = order.ActivateOrder("5f259130a172cf001222f533", &order.ActivateParams{
Active: 1,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("Activate Order: %+v\n", activatedOrder)
Get Order Detail
Retrieve an order's detail. Date format is UTC time.
func GetOrderDetail(orderID string)
Usage example:
var orderDetail, err = order.GetOrderDetail("5f259130a172cf001222f533")
if err != nil {
panic(err.Error())
}
fmt.Printf("Detail Order: %+v\n", orderDetail)
Update Order
Update an order's package's weight and dimension.
func UpdateOrder(orderID string, params *UpdateOrderParams)
Usage example:
var updateOrder, err = order.UpdateOrder("5f259130a172cf001222f533", &order.UpdateOrderParams{
Length: 5,
Width: 5,
Height: 5,
WeightTotal: 1,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("Updated Order: %+v\n", updateOrder)
Cancel Order
Cancel an order.
func CancelOrder(orderID string)
Usage example:
var cancelOrder, err = order.CancelOrder("5f259130a172cf001222f533")
if err != nil {
panic(err.Error())
}
fmt.Printf("Cancel Order: %+v\n", cancelOrder)
Pickup Orders
You need to import pickup
package first by following code:
import "github.com/denifrahman/shipper-go/pickup"
Create Pickup Request
Assign agent and activate orders.
func CreatePickup(params *CreatePickupParams)
Usage examples
var createPickup, err = pickup.CreatePickup(&pickup.CreatePickupParams{
OrderIDs: []string{"5e45538"},
DatePickup: "2020-08-11 10:30:00",
AgentID: 1432,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("Created Pickup: %+v\n", createPickup)
Cancel Pickup Request
Cancel pickup request.
func CancelPickup(params *CancelPickupParams)
Usage example:
cancelPickup, err := pickup.CancelPickup(&pickup.CancelPickupParams{
OrderIDs: []string{"5e45538"},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("Cancelled Pickup: %+v\n", cancelPickup)
Get Agents by Suburb
Get agent by origin suburb ID.
func GetAgents(suburbID int)
Usage example:
agents, err := pickup.GetAgents(1330)
if err != nil {
panic(err.Error())
}
fmt.Printf("List Agents: %+v\n", agents)
Get Pickup Time Slots
Get pickup time slots.
func GetPickupTimeSlots(t *testing.T)
Usage example:
timeslot, err := GetPickupTimeSlots("Asia/Jakarta")
if err != nil {
return
}
fmt.Println(timeslot)
fmt.Printf("List Pickup time slots: %+v\n", timeslot)
Furthermore
Get All Tracking Status
You need to import tracking
package first by following code:
import "github.com/denifrahman/shipper-go/tracking"
func GetAllStatus()
Usage example:
allTrackingStatus, err := tracking.GetAllStatus()
if err != nil {
panic(err.Error())
}
fmt.Printf("List Tracking Status: %+v\n", allTrackingStatus)
Generate AWB Number
Generate AWB from related logistic, in case that AWB number in order is not generated yet when order sent.
You need to import awb
package first by following code:
import "github.com/denifrahman/shipper-go/awb"
func Generate(params *GenerateParams)
Usage example:
generatedAWB, err := awb.Generate(&awb.GenerateParams{
OID: "5f259130a172cf001222f533",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("AWB Number: %+v\n", generatedAWB)
Test
Rename the .env.example
file to .env
and set the API Key with the one you obtained from Shipper. After that, you can run the test by following command:
go test -v ./...
Contributing
For any requests, bugs, or comments, please open an issue or submit a pull request.