Skip to content

vimukthi-git/aftership-sdk-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Picture

Aftership-SDK-GoLang

Introduction:

Aftership provides an API to Track & Notify of shipments from hundreds of couriers worldwide. Aftership-SDK-GoLang is a SDK to develop Apps using Aftership API in go-lang. All endpoints including couriers, tracking and notification are supported.

Contact: support@aftership.com

You will need to create an account at Aftership and obtain an API key first to access Aftership APIs using aftership-go SDK.

Installation

If you already have go installed locally then do,

go get github.com/vimukthi-git/aftership-go/apiV4
go get github.com/vimukthi-git/aftership-go/impl

Example:

  • Getting couriers already added to your account,
package main

import (
        "fmt"
        "github.com/vimukthi-git/aftership-go/apiV4"
        "github.com/vimukthi-git/aftership-go/impl"
)

func main() {
        var api apiV4.CourierHandler = &impl.AfterShipApiV4Impl{
                "<your-api-key>",
                nil,
                nil,
        }
        res, meta := api.GetCouriers()
        if (meta.Code == 200) {
            fmt.Print(res)
        }
        
}
  • Posting a tracking to the API,
package main

import (
        "fmt"
        "github.com/vimukthi-git/aftership-go/apiV4"
        "github.com/vimukthi-git/aftership-go/impl"
)

func main() {
        var api apiV4.TrackingsHandler = &impl.AfterShipApiV4Impl{
                "<your-api-key>",
                nil,
                nil,
        }
        res, meta := api.CreateTracking(apiV4.NewTracking{
                "1Z9999999999999998",
                nil,
                "",
                "",
                "",
                "",
                "",
                nil,
                nil,
                nil,
                nil,
                "",
                "",
                "",
                "",
                "",
                nil,
        })
        
        if (meta.Code == 200) {
            fmt.Print(res)
        }
}
  • Getting Checkpoints and other tracking information for a tracking number,
package main

import (
        "fmt"
        "github.com/vimukthi-git/aftership-go/apiV4"
        "github.com/vimukthi-git/aftership-go/impl"
)

func main() {
        var api apiV4.TrackingsHandler = &impl.AfterShipApiV4Impl{
                "<your-api-key>",
                nil,
                nil,
        }
        res, meta := api.GetTracking(
            apiV4.TrackingId{
                "",
                "xq-express",
                "LS404494276CN",
            }, 
            "",
            "",
        )
        
        if (meta.Code == 200) {
            fmt.Print(res)
        }
}
  • Setting a proxy through which the SDK will make requests is easy since we expose http.Client to the user. Eg:
proxyUrl, err := url.Parse("http://proxyIp:proxyPort")
myClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}

// Instantiate sdk with your own client.
var api apiV4.TrackingsHandler = &impl.AfterShipApiV4Impl{
                "<your-api-key>",
                nil,
                myClient,
        }

Check ./impl/impl_test.go for examples on using all endpoints.

Documentation

About

Go-lang SDK for Aftership API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%