Skip to content

Latest commit

 

History

History
180 lines (132 loc) · 3.77 KB

ups-tracking-api-go.md

File metadata and controls

180 lines (132 loc) · 3.77 KB

UPS Tracking API - Go

Use Go to track UPS shipments with UPS Tracking API.

Features

  • Real-time UPS tracking.
  • Batch UPS tracking.
  • Other features to manage your UPS tracking.

Installation

Installation is easy:

$ go mod init github.com/my/repo
$ go get github.com/trackingmore-api/trackingmore-sdk-go

Quick Start

Get the API key:

To use this API, you need to generate your API key.

  • Click here to access TrackingMore admin.
  • Go to the "Developer" section.

  • Click "Generate API Key".

  • Give a name to your API key, and click "Save" .

Then, start to track your UPS shipments.

Usage

Create a tracking (Real-time tracking):

package main

import (
  "context"
  "fmt"
  "github.com/trackingmore-api/trackingmore-sdk-go"
)

func main() {
  key := "your api key"
  cli, err := trackingmore.NewClient(key)
  
  if err != nil {
    fmt.Println(err)
    return
  }
  
  params := trackingmore.CreateTrackingParams{
    TrackingNumber: "802608005721255486",
    CourierCode:    "ups",
  }      

  result, err := cli.CreateTracking(context.Background(), params)
  if err != nil {
    fmt.Println(err)
    return
  }
  
  fmt.Println(result)
}

Create trackings (Max. 40 tracking numbers create in one call):

package main

import (
  "context"
  "fmt"
  "github.com/trackingmore-api/trackingmore-sdk-go"
)

func main() {
  key := "your api key"
  cli, err := trackingmore.NewClient(key)
  
  if err != nil {
    fmt.Println(err)
    return
  }
  
  params := []trackingmore.CreateTrackingParams{
      {
      TrackingNumber: "1ZC6G8280303220451",
      CourierCode:    "ups",
      },
      {
      TrackingNumber: "1ZR8E2200404839077",
      CourierCode:    "ups",
      },
  }   

  result, err := cli.BatchCreateTrackings(context.Background(), params)
  if err != nil {
    fmt.Println(err)
    return
  }
  
  fmt.Println(result)
}

Get status of the shipment:

package main

import (
  "context"
  "fmt"
  "github.com/trackingmore-api/trackingmore-sdk-go"
)

func main() {
  key := "your api key"
  cli, err := trackingmore.NewClient(key)
  
  if err != nil {
    fmt.Println(err)
    return
  }

  params := trackingmore.GetTrackingResultsParams{
    CreatedDateMin: "2023-08-23T06:00:00+00:00",
    CreatedDateMax: "2023-09-05T07:20:42+00:00",
  }  

  result, err := cli.GetTrackingResults(context.Background(), params)
  if err != nil {
    fmt.Println(err)
    return
  }
  
  fmt.Println(result)
}

Update a tracking by ID:

package main

import (
  "context"
  "fmt"
  "github.com/trackingmore-api/trackingmore-sdk-go"
)

func main() {
  key := "your api key"
  cli, err := trackingmore.NewClient(key)
  
  if err != nil {
    fmt.Println(err)
    return
  }

  params := trackingmore.UpdateTrackingParams{
    CustomerName: "New name",
    Note:         "New tests order note",
  }
  idString := "9a2f732e29b5ed2071d4cf6b5f4a3d19"
  
  result, err := cli.UpdateTrackingByID(context.Background(), idString, params)
  if err != nil {
    fmt.Println(err)
    return
  }
  
  fmt.Println(result)
}