ups

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 43 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Code generated by scripts from manifest.yaml. DO NOT EDIT.

Package ups is a non-official Go SDK for UPS REST APIs.

Generated OpenAPI clients live under internal/generated and are accessed through this package. You must supply your own UPS developer OAuth credentials.

Package ups is an unofficial Go client for UPS REST APIs.

Overview

  • OAuth2 client-credentials with in-memory token cache
  • Sandbox (CIE) vs Production base URLs per API
  • Convenience methods: Rate, CreateShipment, VoidShipment, LabelRecovery, Track, ValidateAddress
  • Accessors for every UPS API listed in scripts/manifest.yaml (*Client methods)

Generated OpenAPI clients live in internal/generated and are not imported by downstream modules directly; use this package instead.

This project is not affiliated with UPS. See DISCLAIMER.md at the module root.

Code generated by generate.sh from scripts/manifest.yaml. DO NOT EDIT.

Index

Constants

View Source
const (
	// EnvSandbox is the UPS Customer Integration Environment (CIE).
	EnvSandbox = "sandbox"
	// EnvProduction is the UPS production environment.
	EnvProduction = "production"

	// DefaultAPIVersion is the path version used by Rate/Ship wrappers when omitted.
	DefaultAPIVersion = "v2409"
)

Variables

This section is empty.

Functions

func BaseURL

func BaseURL(env string) string

BaseURL returns the UPS host (no /api path) for env.

func BasicAuth

func BasicAuth(clientID, clientSecret string) oauthgen.RequestEditorFn

BasicAuth returns a request editor that sets HTTP Basic auth (OAuth token call).

func BearerToken

func BearerToken(token string) func(context.Context, *http.Request) error

BearerToken sets Authorization: Bearer on the request.

func IsProduction

func IsProduction(env string) bool

IsProduction reports whether env is production.

func ServerURL

func ServerURL(env, apiPackage string) string

ServerURL returns the UPS base URL for an API package and environment. env is "production" or anything else (sandbox/CIE).

Types

type APIError

type APIError struct {
	Op         string // e.g. "rate", "ship", "track", "oauth"
	StatusCode int
	Code       string
	Message    string
	Body       string
	Err        error
}

APIError is a normalized UPS / transport error.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

type AddressValidationClient

type AddressValidationClient = av.ClientWithResponses

Re-exported Address Validation types.

type AddressValidationHTTPResponse

type AddressValidationHTTPResponse = av.AddressValidationResponse

Re-exported Address Validation types.

type AddressValidationOptions

type AddressValidationOptions struct {
	Version        string // default "v2"
	RequestOption  int    // 1=validation, 2=classification, 3=both; default 1
	TransID        string
	TransactionSrc string
	Params         *AddressValidationParams
}

AddressValidationOptions controls ValidateAddress.

type AddressValidationParams

type AddressValidationParams = av.AddressValidationParams

Re-exported Address Validation types.

type AddressValidationRequest

type AddressValidationRequest = av.AddressValidationJSONRequestBody

Re-exported Address Validation types.

type Client

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

Client is the hand-written UPS facade (OAuth, retries, API accessors).

func New

func New(cfg Config) *Client

New builds a Client. ClientID and ClientSecret are required for authenticated calls.

func (*Client) AccessToken

func (c *Client) AccessToken(ctx context.Context) (string, error)

AccessToken returns a cached or freshly fetched OAuth access token (client credentials).

func (*Client) AddressValidationClient

func (c *Client) AddressValidationClient() (*AddressValidationClient, error)

AddressValidationClient returns a generated Address Validation client.

func (*Client) AuthedEditors

func (c *Client) AuthedEditors(ctx context.Context, transID, transactionSrc string) ([]func(context.Context, *http.Request) error, error)

AuthedEditors returns Bearer (+ optional headers) request editors after ensuring a token.

func (*Client) CommerceGuardClient

func (c *Client) CommerceGuardClient() (*commerceguard.ClientWithResponses, error)

CommerceGuardClient returns a generated CommerceGuard API client for the configured environment.

func (*Client) CreateShipment

func (c *Client) CreateShipment(ctx context.Context, body ShipmentRequest, opt *ShipmentOptions) (*SHIPResponseWrapper, error)

CreateShipment creates a shipment and returns label payload (base64 in response GraphicImage when requested).

func (*Client) CustomsDetailClient

func (c *Client) CustomsDetailClient() (*customsdetail.ClientWithResponses, error)

CustomsDetailClient returns a generated CustomsDetailV2 API client for the configured environment.

func (*Client) DangerousGoodsClient

func (c *Client) DangerousGoodsClient() (*dangerousgoods.ClientWithResponses, error)

DangerousGoodsClient returns a generated DangerousGoods API client for the configured environment.

func (*Client) DeliveryDefenseClient

func (c *Client) DeliveryDefenseClient() (*deliverydefense.ClientWithResponses, error)

DeliveryDefenseClient returns a generated DeliveryDefense API client for the configured environment.

func (*Client) DeliveryInterceptClient

func (c *Client) DeliveryInterceptClient() (*deliveryintercept.ClientWithResponses, error)

DeliveryInterceptClient returns a generated DeliveryIntercept API client for the configured environment.

func (*Client) Environment

func (c *Client) Environment() string

Environment returns the configured environment name.

func (*Client) ExportAssureClient

func (c *Client) ExportAssureClient() (*exportassure.ClientWithResponses, error)

ExportAssureClient returns a generated UPSExportAssure API client for the configured environment.

func (*Client) ForwardingClient

func (c *Client) ForwardingClient() (*forwarding.ClientWithResponses, error)

ForwardingClient returns a generated Forwarding API client for the configured environment.

func (*Client) GlobalCheckoutClient

func (c *Client) GlobalCheckoutClient() (*globalcheckout.ClientWithResponses, error)

GlobalCheckoutClient returns a generated GlobalCheckout API client for the configured environment.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient returns the underlying HTTP client.

func (*Client) InteractiveGuidanceClient

func (c *Client) InteractiveGuidanceClient() (*interactiveguidance.ClientWithResponses, error)

InteractiveGuidanceClient returns a generated InteractiveDescriptionGuidance API client for the configured environment.

func (*Client) InvalidateToken

func (c *Client) InvalidateToken()

InvalidateToken clears the cached access token (forces refresh on next call).

func (*Client) LabelRecovery

LabelRecovery recovers a previously generated label.

func (*Client) LandedCostClient

func (c *Client) LandedCostClient() (*landedcost.ClientWithResponses, error)

LandedCostClient returns a generated LandedCost API client for the configured environment.

func (*Client) LocatorClient

func (c *Client) LocatorClient() (*locator.ClientWithResponses, error)

LocatorClient returns a generated Locator API client for the configured environment.

func (*Client) OAuthAuthCodeClient

func (c *Client) OAuthAuthCodeClient() (*oauthauthcode.ClientWithResponses, error)

OAuthAuthCodeClient returns a generated OAuthAuthCode API client for the configured environment.

func (*Client) PaperlessClient

func (c *Client) PaperlessClient() (*paperless.ClientWithResponses, error)

PaperlessClient returns a generated Paperless API client for the configured environment.

func (*Client) PickupClient

func (c *Client) PickupClient() (*pickup.ClientWithResponses, error)

PickupClient returns a generated Pickup API client for the configured environment.

func (*Client) PickupNotificationClient

func (c *Client) PickupNotificationClient() (*pickupnotification.ClientWithResponses, error)

PickupNotificationClient returns a generated PickupNotificationPreferences API client for the configured environment.

func (*Client) PickupPointsClient

func (c *Client) PickupPointsClient() (*pickuppoints.ClientWithResponses, error)

PickupPointsClient returns a generated UPSPickupPoints API client for the configured environment.

func (*Client) PreNotificationClient

func (c *Client) PreNotificationClient() (*prenotification.ClientWithResponses, error)

PreNotificationClient returns a generated PreNotification API client for the configured environment.

func (*Client) ProtectedDeliveryTokenClient

func (c *Client) ProtectedDeliveryTokenClient() (*protecteddeliverytoken.ClientWithResponses, error)

ProtectedDeliveryTokenClient returns a generated ProtectedDeliveryToken API client for the configured environment.

func (*Client) QuantumViewClient

func (c *Client) QuantumViewClient() (*quantumview.ClientWithResponses, error)

QuantumViewClient returns a generated QuantumView API client for the configured environment.

func (*Client) Rate

func (c *Client) Rate(ctx context.Context, body RateRequest, opt *RateOptions) (*RATEResponseWrapper, error)

Rate quotes a shipment (supports multi-package via RateRequest.RateRequest.Shipment.Package).

func (*Client) RatingClient

func (c *Client) RatingClient() (*RateClient, error)

RatingClient returns a generated Rating client pointed at the configured environment.

func (*Client) SCSInventoryClient

func (c *Client) SCSInventoryClient() (*scsinventory.ClientWithResponses, error)

SCSInventoryClient returns a generated SCSIngestInventory API client for the configured environment.

func (*Client) SCSLogisticsClient

func (c *Client) SCSLogisticsClient() (*scslogistics.ClientWithResponses, error)

SCSLogisticsClient returns a generated SCSIngestLogistics API client for the configured environment.

func (*Client) SCSTransportationClient

func (c *Client) SCSTransportationClient() (*scstransportation.ClientWithResponses, error)

SCSTransportationClient returns a generated UPSSCSTransportation API client for the configured environment.

func (*Client) ShippingClient

func (c *Client) ShippingClient() (*ShippingClient, error)

ShippingClient returns a generated Shipping client for the configured environment.

func (*Client) SmartPickupClient

func (c *Client) SmartPickupClient() (*smartpickup.ClientWithResponses, error)

SmartPickupClient returns a generated Smart-Pickup-Account-Management API client for the configured environment.

func (*Client) TimeInTransitClient

func (c *Client) TimeInTransitClient() (*timeintransit.ClientWithResponses, error)

TimeInTransitClient returns a generated TimeInTransit API client for the configured environment.

func (*Client) Track

func (c *Client) Track(ctx context.Context, inquiryNumber string, opt *TrackOptions) (*TrackApiResponse, error)

Track retrieves tracking details for an inquiry number (1Z…, etc.).

func (*Client) TrackAlertClient

func (c *Client) TrackAlertClient() (*trackalert.ClientWithResponses, error)

TrackAlertClient returns a generated UPSTrackAlert API client for the configured environment.

func (*Client) TrackAlertEnhancedClient

func (c *Client) TrackAlertEnhancedClient() (*trackalertenhanced.ClientWithResponses, error)

TrackAlertEnhancedClient returns a generated UPSTrackAlertEnhanced API client for the configured environment.

func (*Client) TrackByReference

func (c *Client) TrackByReference(ctx context.Context, referenceNumber string, params *ReferenceTrackingParams, opt *TrackOptions) (*TrackApiResponse, error)

TrackByReference tracks by reference number.

func (*Client) TrackingClient

func (c *Client) TrackingClient() (*TrackingClient, error)

TrackingClient returns a generated Tracking client for the configured environment.

func (*Client) TradeDirectClient

func (c *Client) TradeDirectClient() (*tradedirect.ClientWithResponses, error)

TradeDirectClient returns a generated TradeDirect API client for the configured environment.

func (*Client) ValidateAddress

ValidateAddress validates / classifies an address.

func (*Client) VoidShipment

func (c *Client) VoidShipment(ctx context.Context, shipmentID string, opt *VoidOptions) (*VOIDSHIPMENTResponseWrapper, error)

VoidShipment cancels/voids a shipment by shipment identification number.

func (*Client) WorldEaseClient

func (c *Client) WorldEaseClient() (*worldease.ClientWithResponses, error)

WorldEaseClient returns a generated WorldEaseShipmentManagement API client for the configured environment.

type Config

type Config struct {
	ClientID      string // required for authenticated calls
	ClientSecret  string // required for authenticated calls
	AccountNumber string // optional; sent as x-merchant-id on token requests
	Environment   string // "sandbox" (default) or "production"

	HTTPClient     *http.Client
	Timeout        time.Duration // applied when HTTPClient is nil; default 60s
	TransactionSrc string        // optional default transactionSrc header
	MaxRetries     int           // HTTP retries on 429/5xx; default 2
	Logger         Logger        // optional; nil = no logging
}

Config holds UPS client credentials and runtime options. Pass ClientID / ClientSecret explicitly (from your secret store, DB, flags, etc.). The SDK does not read credentials from the environment.

type LABELRECOVERYRequestWrapper

type LABELRECOVERYRequestWrapper = shipping.LABELRECOVERYRequestWrapper

Re-exported Shipping types.

type LABELRECOVERYResponseWrapper

type LABELRECOVERYResponseWrapper = shipping.LABELRECOVERYResponseWrapper

Re-exported Shipping types.

type LabelRecoveryOptions

type LabelRecoveryOptions struct {
	Version        string
	TransID        string
	TransactionSrc string
	Params         *LabelRecoveryParams
}

LabelRecoveryOptions controls LabelRecovery.

type LabelRecoveryParams

type LabelRecoveryParams = shipping.LabelRecoveryOpParams

Re-exported Shipping types.

type LabelRecoveryRequest

type LabelRecoveryRequest = shipping.LabelRecoveryOpJSONRequestBody

Re-exported Shipping types.

type Logger

type Logger interface {
	Debugf(format string, args ...any)
	Errorf(format string, args ...any)
}

Logger is a minimal structured logger hook.

type RATERequestWrapper

type RATERequestWrapper = rating.RATERequestWrapper

Re-exported Rating types (import path stays github.com/befship/ups-sdk/ups).

type RATEResponseWrapper

type RATEResponseWrapper = rating.RATEResponseWrapper

Re-exported Rating types (import path stays github.com/befship/ups-sdk/ups).

type RateClient

type RateClient = rating.ClientWithResponses

Re-exported Rating types (import path stays github.com/befship/ups-sdk/ups).

type RateHTTPResponse

type RateHTTPResponse = rating.RateOpResponse

Re-exported Rating types (import path stays github.com/befship/ups-sdk/ups).

type RateOptions

type RateOptions struct {
	Version        string // default DefaultAPIVersion
	RequestOption  string // Rate | Shop | Ratetimeintransit | Shoptimeintransit; default "Rate"
	AdditionalInfo string // e.g. "timeintransit"
	TransID        string
	TransactionSrc string
}

RateOptions controls the Rate API call.

type RateParams

type RateParams = rating.RateOpParams

Re-exported Rating types (import path stays github.com/befship/ups-sdk/ups).

type RateRequest

type RateRequest = rating.RateOpJSONRequestBody

Re-exported Rating types (import path stays github.com/befship/ups-sdk/ups).

type ReferenceTrackingParams

type ReferenceTrackingParams = tracking.ReferenceTrackingAPIParams

Re-exported Tracking types.

type SHIPRequestWrapper

type SHIPRequestWrapper = shipping.SHIPRequestWrapper

Re-exported Shipping types.

type SHIPResponseWrapper

type SHIPResponseWrapper = shipping.SHIPResponseWrapper

Re-exported Shipping types.

type ShipmentHTTPResponse

type ShipmentHTTPResponse = shipping.ShipmentOpResponse

Re-exported Shipping types.

type ShipmentOptions

type ShipmentOptions struct {
	Version                     string // default DefaultAPIVersion
	AdditionalAddressValidation string
	TransID                     string
	TransactionSrc              string
}

ShipmentOptions controls CreateShipment.

type ShipmentParams

type ShipmentParams = shipping.ShipmentOpParams

Re-exported Shipping types.

type ShipmentRequest

type ShipmentRequest = shipping.ShipmentOpJSONRequestBody

Re-exported Shipping types.

type ShipmentTrackingParams

type ShipmentTrackingParams = tracking.ShipmentTrackingAPIParams

Re-exported Tracking types.

type ShippingClient

type ShippingClient = shipping.ClientWithResponses

Re-exported Shipping types.

type TrackApiResponse

type TrackApiResponse = tracking.TrackApiResponse

Re-exported Tracking types.

type TrackHTTPResponse

Re-exported Tracking types.

type TrackOptions

type TrackOptions struct {
	TransID        string
	TransactionSrc string
	Params         *TrackParams
}

TrackOptions controls Track.

type TrackParams

Re-exported Tracking types.

type TrackingClient

type TrackingClient = tracking.ClientWithResponses

Re-exported Tracking types.

type VOIDSHIPMENTResponseWrapper

type VOIDSHIPMENTResponseWrapper = shipping.VOIDSHIPMENTResponseWrapper

Re-exported Shipping types.

type VoidOptions

type VoidOptions struct {
	Version        string
	TransID        string
	TransactionSrc string
	Params         *VoidShipmentParams
}

VoidOptions controls VoidShipment.

type VoidShipmentHTTPResponse

type VoidShipmentHTTPResponse = shipping.VoidShipmentOpResponse

Re-exported Shipping types.

type VoidShipmentParams

type VoidShipmentParams = shipping.VoidShipmentOpParams

Re-exported Shipping types.

type XAVRequestWrapper

type XAVRequestWrapper = av.XAVRequestWrapper

Re-exported Address Validation types.

type XAVResponseWrapper

type XAVResponseWrapper = av.XAVResponseWrapper

Re-exported Address Validation types.

Jump to

Keyboard shortcuts

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