Unofficial library for access Shipper API from applications written with Go.
- Installation
- Usage
- Available Methods and Examples
- Test
- Contributing
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"
Configure package with your account's API key obtained from Shipper.
shipper.Conf.SetAPIKey("API_KEY")
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)
You need to import location
package first by following code:
import "github.com/denifrahman/shipper-go/location"
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)
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)
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)
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)
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)
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)
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)
You need to import rates
package first by following code:
import "github.com/denifrahman/shipper-go/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)
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)
You need to import order
package first by following code:
import "github.com/denifrahman/shipper-go/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)
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)
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/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)
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 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 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)
You need to import pickup
package first by following code:
import "github.com/denifrahman/shipper-go/pickup"
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.
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 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.
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)
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 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)
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 ./...
For any requests, bugs, or comments, please open an issue or submit a pull request.