sendcloud

package module
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 9 Imported by: 0

README

build

sendcloud-go

An API-client for Sendcloud written in Golang.

Overview GoDoc

This package currently supports:

  • parcels
  • parcel documents
  • labels
  • methods
  • addresses
  • integrations

Install

go get github.com/afosto/sendcloud-go

Examples

Some examples on how to use the client are found below.

To initialize the client:

api := client.API{}
api.Init("api_key", "api_secret")

To list shipping methods:

methods, err := api.Method.GetMethods()
if err != nil {
    log.Fatal(err)
}

for _, m := range methods {
    log.Print(*m)
}

Create a parcel:

params := &sendcloud.ParcelParams{
	Name:             "Sendcloud-GO",
	CompanyName:      "Afosto SaaS BV",
	Street:           "Grondzijl",
	HouseNumber:      "16",
	City:             "Groningen",
	PostalCode:       "9731DG",
	PhoneNumber:      "0507119519",
	EmailAddress:     "peter@afosto.io",
	CountryCode:      "NL",
	IsLabelRequested: true,
	Method:           8,
	ExternalID:       uuid.New().String(),
}
parcel, err := api.Parcel.New(params)

resolve a service point id from postnl,dhl,dpd to a sendcloud service point id

spid, err := api.ServicePoint.GetServicePoint(servicepoint.Matcher{
    SPID:        "NL-972301",
    Carrier:     "dhl",
    Country:     "NL",
    PostalCode:  "9731AR",
    HouseNumber: "41",
    Latitude:    53.226994,
    Longitude:   6.608120,
})

fmt.PrintLn(spid) 

this service point id can then be placed on an parcel on creation

Contributing

All contributions / suggestions are welcome. Please raise an issue or submit a PR.

Thanks

This package was heavily inspired by stripe-go.

Author

This package is developed by Afosto SaaS BV.

License

MIT.

Documentation

Overview

Sendcloud-go is an api client for Sendcloud

It currently supports parcels, labels, integrations, methods and sender addresses and will make interaction easier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool added in v0.4.7

func Bool(b bool) *bool

Helper functions for creating pointers. Useful if constructing OptionParams manually with more specific filters.

func Float64 added in v0.4.7

func Float64(f float64) *float64

func Int added in v0.4.7

func Int(i int) *int

func Int64 added in v0.4.7

func Int64(i int64) *int64

func NewRequest added in v0.4.5

func NewRequest(ctx context.Context, method, uri string, payload Payload, apiKey, apiSecret string) (*http.Request, error)

NewRequest creates and prepares a *http.Request with the given method, url, payload and credentials, so it's ready to be sent to Sendcloud.

func Request

func Request(method, uri string, payload Payload, apiKey, apiSecret string, r Response) error

Request sends a request to Sendcloud with given method, path, payload and credentials.

func String added in v0.4.7

func String(s string) *string

func ValidateResponse added in v0.4.5

func ValidateResponse(response *http.Response) error

ValidateResponse validates a received response from Sendcloud. It is valid and returns nil when the status code is between 200 and 299.

Types

type Address added in v0.4.6

type Address struct {
	Name         string `json:"name"`
	CompanyName  string `json:"company_name,omitempty"`
	AddressLine1 string `json:"address_line_1,omitempty"`
	AddressLine2 string `json:"address_line_2,omitempty"`
	HouseNumber  string `json:"house_number,omitempty"`
	PostalCode   string `json:"postal_code,omitempty"`
	City         string `json:"city,omitempty"`
	CountryCode  string `json:"country_code,omitempty"`
	Email        string `json:"email,omitempty"`
	PhoneNumber  string `json:"phone_number,omitempty"`
}

Address represents a Sendcloud address.

type AddressDivided

type AddressDivided struct {
	Street      string `json:"street"`
	HouseNumber string `json:"house_number"`
}

type BilledWeight added in v0.4.7

type BilledWeight struct {
	Value      string `json:"value"`
	Unit       string `json:"unit"`
	Volumetric bool   `json:"volumetric"`
}

BilledWeight indicates the weight used for billing, considering volumetric weight.

type Carrier

type Carrier struct {
	Code string `json:"code"`
}

type CarrierOption added in v0.4.7

type CarrierOption struct {
	Code string `json:"code,omitempty"`
	Name string `json:"name,omitempty"`
}

Carrier represents carrier information.

type CarrierShippingFunctionalities added in v0.4.7

type CarrierShippingFunctionalities struct {
	AgeCheck             *int    `json:"age_check"`
	B2B                  bool    `json:"b2b"`
	B2C                  bool    `json:"b2c"`
	Boxable              bool    `json:"boxable"`
	BulkyGoods           bool    `json:"bulky_goods"`
	CarrierBillingType   string  `json:"carrier_billing_type"`
	CashOnDelivery       *int    `json:"cash_on_delivery"`
	DangerousGoods       bool    `json:"dangerous_goods"`
	DeliveryAttempts     *int    `json:"delivery_attempts"`
	DeliveryBefore       string  `json:"delivery_before"`
	DeliveryDeadline     string  `json:"delivery_deadline"`
	EcoDelivery          bool    `json:"eco_delivery"`
	ERS                  bool    `json:"ers"`
	FirstMile            string  `json:"first_mile"`
	FlexDelivery         bool    `json:"flex_delivery"`
	FormFactor           *string `json:"form_factor"`
	FragileGoods         bool    `json:"fragile_goods"`
	FreshGoods           bool    `json:"fresh_goods"`
	HarmonizedLabel      bool    `json:"harmonized_label"`
	IDCheck              bool    `json:"id_check"`
	Incoterm             string  `json:"incoterm"`
	Insurance            *int    `json:"insurance"`
	Labelless            bool    `json:"labelless"`
	LastMile             string  `json:"last_mile"`
	Manually             bool    `json:"manually"`
	Multicollo           bool    `json:"multicollo"`
	NeighborDelivery     bool    `json:"neighbor_delivery"`
	NonConveyable        bool    `json:"non_conveyable"`
	PersonalizedDelivery bool    `json:"personalized_delivery"`
	PickUp               bool    `json:"pick_up"`
	Premium              bool    `json:"premium"`
	Priority             string  `json:"priority"`
	RegisteredDelivery   bool    `json:"registered_delivery"`
	Returns              bool    `json:"returns"`
	Segment              string  `json:"segment"`
	ServiceArea          string  `json:"service_area"`
	Signature            bool    `json:"signature"`
	Size                 string  `json:"size"`
	Sorted               bool    `json:"sorted"`
	Surcharge            bool    `json:"surcharge"`
	Tracked              bool    `json:"tracked"`
	Tyres                bool    `json:"tyres"`
	WeekendDelivery      string  `json:"weekend_delivery"`
}

CarrierShippingFunctionalities defines various features or attributes of a shipping option from the API response. Pointers are used for fields that can be 'null' in the API response.

type Contract added in v0.4.7

type Contract struct {
	ID          int64  `json:"id,omitempty"`
	ClientID    string `json:"client_id,omitempty"`
	CarrierCode string `json:"carrier_code,omitempty"`
	Name        string `json:"name,omitempty"`
}

Contract represents a carrier contract.

type Country

type Country struct {
	Code   string
	Amount int64
}

type CountryResponse

type CountryResponse struct {
	Iso2          string   `json:"iso_2"`
	Iso3          string   `json:"iso_3"`
	ID            int      `json:"id"`
	Price         float64  `json:"price"`
	Name          string   `json:"name"`
	LeadTimeHours *float64 `json:"lead_time_hours"`
}

type CreateParcelItemRequest added in v0.4.0

type CreateParcelItemRequest struct {
	// Harmonized System Code Wikipedia Link. Providing a complete HS code with 8 characters increases the delivery rate.
	HsCode string `json:"hs_code"`
	// Weight of a single item in kilograms.
	Weight string `json:"weight"`
	// Quantity of items shipped.
	Quantity int `json:"quantity"`
	// Description of the item.
	Description string `json:"description"`
	// ISO-2 code of the country where the items were originally produced. External Link.
	OriginCountry string `json:"origin_country,omitempty"`
	// Value of a single item.
	Value float64 `json:"value"`
	// The SKU of the product.
	SKU string `json:"sku,omitempty"`
	// External ID of the item generated by a shop system or similar.
	ItemId string `json:"item_id,omitempty"`
	// The list of properties of the product. Used as a JSON object with {‘key’: ‘value’}.
	Properties map[string]interface{} `json:"properties,omitempty"`
}

type CreateParcelShipmentRequest added in v0.4.0

type CreateParcelShipmentRequest struct {
	ID int64 `json:"id"`
}

type CustomsInformation added in v0.4.6

type CustomsInformation struct {
	InvoiceNumber string `json:"invoice_number"`
	ExportReason  string `json:"export_reason"`
	ExportType    string `json:"export_type"`  // e.g., "commercial_goods"
	InvoiceDate   string `json:"invoice_date"` // ISO 8601 date (e.g., "2023-08-24")
}

CustomsInformation holds customs-related details for international returns.

type CustomsShipmentType added in v0.4.0

type CustomsShipmentType int
const (
	CustomsShipmentTypeGift CustomsShipmentType = iota
	CustomsShipmentTypeDocuments
	CustomsShipmentTypeCommercialGoods
	CustomsShipmentTypeCommercialSample
	CustomsShipmentTypeReturnedGoods
)

type Dimension added in v0.4.6

type Dimension struct {
	Length float64 `json:"length"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
	Unit   string  `json:"unit"`
}

Dimension specifies the size of a single collo.

type Document added in v0.4.5

type Document struct {
	Format DocumentFormat
	Body   []byte
}

Document represents a document file that can be downloaded from the api.

type DocumentFormat added in v0.4.5

type DocumentFormat string

DocumentFormat is any of the formats a Document can be in.

const (
	DocumentPdf DocumentFormat = "application/pdf"
	DocumentZpl DocumentFormat = "application/zpl"
	DocumentPng DocumentFormat = "image/png"
)

func (DocumentFormat) Name added in v0.4.5

func (df DocumentFormat) Name() string

func (DocumentFormat) String added in v0.4.5

func (df DocumentFormat) String() string

type Error

type Error struct {
	Code    int    `json:"code"`
	Request string `json:"request"`
	Message string `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

type ErrorResponse

type ErrorResponse struct {
	Error struct {
		Code    int    `json:"code"`
		Request string `json:"request"`
		Message string `json:"message"`
	} `json:"error"`
}

type FunctionalityFilter added in v0.4.7

type FunctionalityFilter struct {
	Returns *bool `json:"returns,omitempty"`
}

FunctionalityFilter allows specifying functionality-based filters. For the simplified client, only 'Returns' will be used.

type Integration

type Integration struct {
	ID                    int64
	Name                  string
	URL                   string
	Type                  string
	IsServicePointEnabled bool
	ServicePointCarriers  []string
	IsWebhooksEnabled     bool
	WebhookURL            string
	UpdatedAt             time.Time
}

type IntegrationListResponseContainer

type IntegrationListResponseContainer []IntegrationResponseContainer

func (*IntegrationListResponseContainer) GetResponse

func (i *IntegrationListResponseContainer) GetResponse() interface{}

Get formatted response

func (*IntegrationListResponseContainer) SetResponse

func (i *IntegrationListResponseContainer) SetResponse(body []byte) error

Set the response

type IntegrationParams

type IntegrationParams struct {
	ID                int64
	Name              string
	URL               string
	IsWebhooksEnabled bool
	WebhookURL        string
}

func (*IntegrationParams) GetPayload

func (i *IntegrationParams) GetPayload() interface{}

type IntegrationRequest

type IntegrationRequest struct {
	ShopName             string   `json:"shop_name"`
	ShopURL              string   `json:"shop_url"`
	ServicePointEnabled  bool     `json:"service_point_enabled"`
	ServicePointCarriers []string `json:"service_point_carriers"`
	WebhookActive        bool     `json:"webhook_active"`
	WebhookURL           string   `json:"webhook_url"`
}

type IntegrationResponseContainer

type IntegrationResponseContainer struct {
	ID                   int64     `json:"id"`
	ShopName             string    `json:"shop_name"`
	ShopURL              string    `json:"shop_url"`
	System               string    `json:"system"`
	FailingSince         string    `json:"failing_since"`
	LastFetch            string    `json:"last_fetch"`
	LastUpdatedAt        time.Time `json:"last_updated_at"`
	ServicePointEnabled  bool      `json:"service_point_enabled"`
	ServicePointCarriers []string  `json:"service_point_carriers"`
	WebhookActive        bool      `json:"webhook_active"`
	WebhookURL           string    `json:"webhook_url"`
}

func (*IntegrationResponseContainer) GetResponse

func (r *IntegrationResponseContainer) GetResponse() interface{}

Get formatted response

func (*IntegrationResponseContainer) SetResponse

func (r *IntegrationResponseContainer) SetResponse(body []byte) error

Set the response

type LabelData

type LabelData []byte

func (LabelData) GetResponse

func (l LabelData) GetResponse() interface{}

Get formatted response

func (*LabelData) SetResponse

func (l *LabelData) SetResponse(body []byte) error

Set the response

type LabelResponse

type LabelResponse struct {
	NormalPrinter []string `json:"normal_printer"`
	LabelPrinter  string   `json:"label_printer"`
}

type LabelResponseContainer

type LabelResponseContainer struct {
	Label LabelResponse `json:"label"`
}

type LeadTimeFilter added in v0.4.7

type LeadTimeFilter struct {
	GT  *float64 `json:"gt,omitempty"`
	GTE *float64 `json:"gte,omitempty"`
	EQ  *float64 `json:"eq,omitempty"`
	LT  *float64 `json:"lt,omitempty"`
	LTE *float64 `json:"lte,omitempty"`
}

LeadTimeFilter allows filtering shipping options based on lead time.

type Method

type Method struct {
	ID             int64
	Name           string
	CarrierCode    string
	IsServicePoint bool
	Amount         int64
	MinWeight      int64
	MaxWeight      int64
	Countries      []Country
}

type MethodListResponseContainer

type MethodListResponseContainer struct {
	ShippingMethods []MethodResponse `json:"shipping_methods"`
}

func (*MethodListResponseContainer) GetResponse

func (a *MethodListResponseContainer) GetResponse() interface{}

func (*MethodListResponseContainer) SetResponse

func (a *MethodListResponseContainer) SetResponse(body []byte) error

Set the response

type MethodResponse

type MethodResponse struct {
	ServicePointInput string            `json:"service_point_input"`
	MaxWeight         string            `json:"max_weight"`
	Name              string            `json:"name"`
	Carrier           string            `json:"carrier"`
	Countries         []CountryResponse `json:"countries"`
	MinWeight         string            `json:"min_weight"`
	ID                int64             `json:"id"`
	Price             float64           `json:"price"`
}

func (*MethodResponse) ToMethod

func (sm *MethodResponse) ToMethod() *Method

Parse methods to a stricter format

type MethodResponseContainer

type MethodResponseContainer struct {
	ShippingMethod MethodResponse `json:"shipping_method"`
}

func (*MethodResponseContainer) GetResponse

func (m *MethodResponseContainer) GetResponse() interface{}

Get formatted response

func (*MethodResponseContainer) SetResponse

func (m *MethodResponseContainer) SetResponse(body []byte) error

Set the response

type OptionDimension added in v0.4.7

type OptionDimension struct {
	Length string `json:"length"`
	Width  string `json:"width"`
	Height string `json:"height"`
	Unit   string `json:"unit"` // e.g., "cm", "m"
}

OptionDimension specifies dimensions for shipping options in a request. Values are strings as per the OpenAPI specification for request bodies.

type OptionParams added in v0.4.7

type OptionParams struct {
	FromCountryCode     *string              `json:"from_country_code,omitempty"`
	ToCountryCode       *string              `json:"to_country_code,omitempty"`
	Functionalities     *FunctionalityFilter `json:"functionalities,omitempty"`
	CarrierCode         *string              `json:"carrier_code,omitempty"`
	ContractID          *int64               `json:"contract_id,omitempty"`
	ShippingProductCode *string              `json:"shipping_product_code,omitempty"`
	Dimensions          *OptionDimension     `json:"dimensions,omitempty"` // For request body
	Weight              *OptionWeight        `json:"weight,omitempty"`     // For request body
	FromPostalCode      *string              `json:"from_postal_code,omitempty"`
	ToPostalCode        *string              `json:"to_postal_code,omitempty"`
	TotalInsurance      *float64             `json:"total_insurance,omitempty"`
	LeadTime            *LeadTimeFilter      `json:"lead_time,omitempty"`
}

OptionParams represents the parameters for fetching shipping options. For the simplified client methods (GetDeliveryShippingOptions, GetReturnShippingOptions), only Functionalities.Returns will be set.

func (*OptionParams) GetPayload added in v0.4.7

func (p *OptionParams) GetPayload() interface{}

GetPayload returns the OptionParams itself, as it directly matches the API request body structure.

type OptionResponse added in v0.4.7

type OptionResponse struct {
	Data []*ShippingOption `json:"data"` // 'data' can be an array or null according to API spec.
}

OptionResponse is the top-level structure for the shipping options API response.

func (*OptionResponse) GetResponse added in v0.4.7

func (r *OptionResponse) GetResponse() interface{}

GetResponse returns the OptionResponse struct itself.

func (*OptionResponse) SetResponse added in v0.4.7

func (r *OptionResponse) SetResponse(body []byte) error

SetResponse unmarshals the API response body into the OptionResponse struct.

type OptionWeight added in v0.4.7

type OptionWeight struct {
	Value string `json:"value"` // e.g. "2.0"
	Unit  string `json:"unit"`  // e.g., "kg", "g"
}

OptionWeight specifies weight for shipping options in a request. Value is a string as per the OpenAPI specification for request bodies.

type Parcel

type Parcel struct {
	ID             int64       `json:"id"`
	ExternalID     *string     `json:"external_id"`
	Name           string      `json:"name"`
	CompanyName    string      `json:"company_name"`
	Email          string      `json:"email"`
	Street         string      `json:"street"`
	HouseNumber    string      `json:"house_number"`
	Address        string      `json:"address"`
	Address2       string      `json:"address_2"`
	City           string      `json:"city"`
	PostalCode     string      `json:"postal_code"`
	CountryCode    string      `json:"country_code"`
	Method         int64       `json:"method"`
	PhoneNumber    *string     `json:"phone_number"`
	TrackingNumber string      `json:"tracking_number"`
	TrackingUrl    string      `json:"tracking_url"`
	ServicePointID *int64      `json:"to_service_point"`
	Weight         string      `json:"weight"`
	Status         Status      `json:"status"`
	Label          string      `json:"label"`
	OrderNumber    string      `json:"order_number"`
	IsReturn       bool        `json:"is_return"`
	Note           *string     `json:"note"`
	CarrierCode    string      `json:"carrier"`
	Data           interface{} `json:"data"`
	CreatedAt      time.Time   `json:"created_at"`
}

type ParcelListResponseContainer

type ParcelListResponseContainer struct {
	Parcels []*ParcelResponse `json:"parcel"`
}

type ParcelParams

type ParcelParams struct {
	Name             string
	CompanyName      string
	Street           string
	HouseNumber      string
	City             string
	PostalCode       string
	State            string
	CountryCode      string
	AdditionalInfo   string
	IsLabelRequested bool
	Method           int64
	EmailAddress     string
	PhoneNumber      string
	ExternalID       string
	ToServicePointID int64
	Weight           string
	OrderNumber      string
	SenderID         int64
	Items            []CreateParcelItemRequest
	// The currency of the total order value. Validated against a format of
	// “XYZ” (ISO 4217).
	TotalOrderValueCurrency *string
	// The value paid by the buyer (via various payment methods supported by the
	// shop(cash on delivery, pre-paid or post-paid), it will also be used for
	// the cash on delivery amount for example “99.99”.
	TotalOrderValue *string
	// Shipping method name selected by buyer during the checkout
	ShippingMethodCheckoutName *string
	// Customs invoice number
	CustomsInvoiceNr *string
	// Customs shipment type
	CustomsShipmentType *CustomsShipmentType
	// When set to true configured shipping rules will be applied before creating the label and announcing the Parcel
	ApplyShippingRules *bool
}

func (*ParcelParams) GetPayload

func (p *ParcelParams) GetPayload() interface{}

Translate the params into an actual request body

type ParcelRequest

type ParcelRequest struct {
	Name                       string                       `json:"name"`
	CompanyName                string                       `json:"company_name"`
	Address                    string                       `json:"address"`
	Address2                   string                       `json:"address_2"`
	HouseNumber                string                       `json:"house_number"`
	City                       string                       `json:"city"`
	PostalCode                 string                       `json:"postal_code"`
	CountryState               string                       `json:"country_state"`
	Country                    string                       `json:"country"`
	Weight                     string                       `json:"weight,omitempty"`
	Telephone                  string                       `json:"telephone"`
	Email                      string                       `json:"email"`
	RequestLabel               bool                         `json:"request_label"`
	ToServicePointID           *int64                       `json:"to_service_point,omitempty"`
	OrderNumber                string                       `json:"order_number"`
	ExternalID                 *string                      `json:"external_reference,omitempty"`
	SenderID                   *int64                       `json:"sender_address,omitempty"`
	Shipment                   *CreateParcelShipmentRequest `json:"shipment,omitempty"`
	Items                      []CreateParcelItemRequest    `json:"parcel_items,omitempty"`
	TotalOrderValueCurrency    *string                      `json:"total_order_value_currency,omitempty"`
	TotalOrderValue            *string                      `json:"total_order_value,omitempty"`
	ShippingMethodCheckoutName *string                      `json:"shipping_method_checkout_name,omitempty"`
	CustomsInvoiceNr           *string                      `json:"customs_invoice_nr,omitempty"`
	CustomsShipmentType        *CustomsShipmentType         `json:"customs_shipment_type,omitempty"`
	ApplyShippingRules         *bool                        `json:"apply_shipping_rules,omitempty"`
}

type ParcelRequestContainer

type ParcelRequestContainer struct {
	Parcel ParcelRequest `json:"parcel"`
}

type ParcelResponse

type ParcelResponse struct {
	ID                  int64           `json:"id"`
	Address             string          `json:"address"`
	Address2            string          `json:"address_2"`
	AddressDivided      AddressDivided  `json:"address_divided"`
	City                string          `json:"city"`
	CompanyName         string          `json:"company_name"`
	Country             CountryResponse `json:"country"`
	Data                interface{}     `json:"data"`
	DateCreated         string          `json:"date_created"`
	Email               string          `json:"email"`
	Name                string          `json:"name"`
	PostalCode          string          `json:"postal_code"`
	Reference           string          `json:"reference"`
	Shipment            Shipment        `json:"shipment"`
	Status              Status          `json:"status"`
	ToServicePointID    *int64          `json:"to_service_point"`
	Telephone           *string         `json:"telephone"`
	TrackingNumber      string          `json:"tracking_number"`
	TrackingUrl         string          `json:"tracking_url"`
	Weight              string          `json:"weight"`
	Label               LabelResponse   `json:"label"`
	OrderNumber         string          `json:"order_number"`
	InsuredValue        int64           `json:"insured_value"`
	TotalInsuredValue   int64           `json:"total_insured_value"`
	ToState             interface{}     `json:"to_state"`
	CustomsInvoiceNr    string          `json:"customs_invoice_nr"`
	CustomsShipmentType interface{}     `json:"customs_shipment_type"`
	Type                interface{}     `json:"type"`
	ShipmentUUID        *string         `json:"shipment_uuid"`
	ShippingMethod      int64           `json:"shipping_method"`
	ExternalOrderID     *string         `json:"external_order_id"`
	ExternalShipmentID  *string         `json:"external_shipment_id"`
	ExternalReference   *string         `json:"external_reference"`
	IsReturn            bool            `json:"is_return"`
	Note                *string         `json:"note"`
	Carrier             Carrier         `json:"carrier"`
}

type ParcelResponseContainer

type ParcelResponseContainer struct {
	Parcel ParcelResponse `json:"parcel"`
}

func (*ParcelResponseContainer) GetResponse

func (p *ParcelResponseContainer) GetResponse() interface{}

Handle the response and returns it as a Parcel{}

func (*ParcelResponseContainer) SetResponse

func (p *ParcelResponseContainer) SetResponse(body []byte) error

Set the response

type Payload

type Payload interface {
	GetPayload() interface{}
}

type Price added in v0.4.6

type Price struct {
	Value    float64 `json:"value"`
	Currency string  `json:"currency"`
}

Price represents a monetary amount.

type Product added in v0.4.6

type Product struct {
	Name                 string `json:"name"`
	Code                 string `json:"code"`
	Carrier              string `json:"carrier"`
	ServicePointsCarrier string `json:"service_points_carrier"`
	WeightRange          struct {
		MinWeight int `json:"min_weight"`
		MaxWeight int `json:"max_weight"`
	} `json:"weight_range"`
	Methods []struct {
		Id                  int    `json:"id"`
		Name                string `json:"name"`
		ShippingProductCode string `json:"shipping_product_code"`
		Properties          struct {
			MinWeight     int `json:"min_weight"`
			MaxWeight     int `json:"max_weight"`
			MaxDimensions struct {
				Length int    `json:"length"`
				Width  int    `json:"width"`
				Height int    `json:"height"`
				Unit   string `json:"unit"`
			} `json:"max_dimensions"`
		} `json:"properties"`
		LeadTimeHours struct {
			NL struct {
				NL int `json:"NL"`
			} `json:"NL"`
		} `json:"lead_time_hours"`
	} `json:"methods"`
}

type ProductListResponseContainer added in v0.4.6

type ProductListResponseContainer struct {
	Products []Product `json:"products"`
}

func (*ProductListResponseContainer) GetResponse added in v0.4.6

func (p *ProductListResponseContainer) GetResponse() interface{}

func (*ProductListResponseContainer) SetResponse added in v0.4.6

func (p *ProductListResponseContainer) SetResponse(body []byte) error

type ProductResponseContainer added in v0.4.6

type ProductResponseContainer struct {
	Product Product `json:"product"`
}

func (*ProductResponseContainer) GetResponse added in v0.4.6

func (p *ProductResponseContainer) GetResponse() interface{}

type QuotePrice added in v0.4.7

type QuotePrice struct {
	Breakdown []*ShippingPriceBreakdownItem `json:"breakdown,omitempty"`
	Total     *ResponsePrice                `json:"total,omitempty"`
}

QuotePrice contains the total price and its breakdown for a shipping quote.

type QuoteWeightRange added in v0.4.7

type QuoteWeightRange struct {
	Min ResponseWeight `json:"min,omitempty"`
	Max ResponseWeight `json:"max,omitempty"`
}

QuoteWeightRange defines the weight range for a specific quote.

type Requirements added in v0.4.7

type Requirements struct {
	Fields          []string `json:"fields,omitempty"`
	ExportDocuments bool     `json:"export_documents"`
}

Requirements indicate necessary fields or documents for a shipping option.

type Response

type Response interface {
	GetResponse() interface{}
	SetResponse(body []byte) error
}

type ResponseDimension added in v0.4.7

type ResponseDimension struct {
	Length string `json:"length"`
	Width  string `json:"width"`
	Height string `json:"height"`
	Unit   string `json:"unit"`
}

ResponseDimension specifies dimensions from an API response. Values are strings as per the OpenAPI specification.

type ResponsePrice added in v0.4.7

type ResponsePrice struct {
	Value    string `json:"value"`
	Currency string `json:"currency"`
}

ResponsePrice represents a monetary value with currency from an API response. Value is a string as per the OpenAPI specification.

type ResponseWeight added in v0.4.7

type ResponseWeight struct {
	Value string `json:"value"`
	Unit  string `json:"unit"`
}

ResponseWeight specifies weight from an API response. Value is a string as per the OpenAPI specification.

type ReturnItemRequest added in v0.4.6

type ReturnItemRequest struct {
	ItemID         string                 `json:"item_id,omitempty"`
	Description    string                 `json:"description,omitempty"`
	Quantity       int                    `json:"quantity,omitempty"`
	Weight         Weight                 `json:"weight"` // weight as string, e.g. "0.4"
	Price          Price                  `json:"price,omitempty"`
	HSCode         string                 `json:"hs_code,omitempty"` // Harmonized System Code (e.g. "6205.20")
	OriginCountry  string                 `json:"origin_country,omitempty"`
	SKU            string                 `json:"sku,omitempty"`
	ProductID      string                 `json:"product_id,omitempty"`
	ReturnReasonID string                 `json:"return_reason_id,omitempty"`
	ReturnMessage  string                 `json:"return_message,omitempty"`
	Properties     map[string]interface{} `json:"properties,omitempty"`
}

ReturnItemRequest represents a single returns item.

type ReturnParams added in v0.4.6

type ReturnParams struct {
	// FROM address details
	FromName         string
	FromCompanyName  string
	FromAddressLine1 string
	FromAddressLine2 string
	FromHouseNumber  string
	FromPostalCode   string
	FromCity         string
	FromCountryCode  string
	FromEmail        string
	FromPhoneNumber  string

	// TO address details
	ToName         string
	ToCompanyName  string
	ToAddressLine1 string
	ToAddressLine2 string
	ToHouseNumber  string
	ToPostalCode   string
	ToCity         string
	ToCountryCode  string
	ToEmail        string
	ToPhoneNumber  string

	// Shipping method details for the returns.
	ShipWithType        string                 // "shipping_option_code" or "shipping_product_code"
	ShippingOptionCode  string                 // Required if ShipWithType is "shipping_option_code"
	ShippingProductCode string                 // Required if ShipWithType is "shipping_product_code"
	Functionalities     map[string]interface{} // Optional shipping functionalities (e.g., {"labelless": true})
	Contract            int64                  // Carrier contract id if more than one active contract exists

	// Parcel specifications
	DimensionLength float64 // Length of a single collo
	DimensionWidth  float64 // Width of a single collo
	DimensionHeight float64 // Height of a single collo
	DimensionUnit   string  // e.g. "cm"

	WeightValue float64 // Total weight in kilograms
	WeightUnit  string  // e.g. "kg"

	// Return-specific details
	ColloCount         int                 // Number of collos (default is 1)
	ParcelItems        []ReturnItemRequest // List of items included in the returns (mandatory for outside-EU returns)
	SendTrackingEmails bool                // When true, Sendcloud sends tracking emails
	BrandID            int64               // ID of the brand for this returns
	TotalInsuredValue  *Price              // Optional insured value
	OrderNumber        string              // Order number associated with the returns
	ExternalReference  string              // Unique user-generated reference
	CustomsInvoiceNr   *string             // Customs invoice number; required for international returns
	DeliveryOption     string              // e.g. "drop_off_point", "in_store", etc.
	CustomsInformation *CustomsInformation // Optional customs information for international returns
	ApplyRules         *bool               // When true, returns rules are applied (rules take precedence)
}

func (*ReturnParams) GetPayload added in v0.4.6

func (r *ReturnParams) GetPayload() interface{}

GetPayload converts ReturnParams into a request payload.

type ReturnRequest added in v0.4.6

type ReturnRequest struct {
	FromAddress        Address             `json:"from_address"`
	ToAddress          Address             `json:"to_address"`
	ShipWith           ShipWith            `json:"ship_with,omitempty"`
	Dimensions         Dimension           `json:"dimensions"`
	Weight             Weight              `json:"weight,omitempty"`
	ColloCount         int                 `json:"collo_count,omitempty"`
	ParcelItems        []ReturnItemRequest `json:"parcel_items,omitempty"`
	SendTrackingEmails bool                `json:"send_tracking_emails"`
	BrandID            int64               `json:"brand_id,omitempty"`
	TotalInsuredValue  *Price              `json:"total_insured_value,omitempty"`
	OrderNumber        string              `json:"order_number,omitempty"`
	TotalOrderValue    *Price              `json:"total_order_value,omitempty"`
	ExternalReference  *string             `json:"external_reference,omitempty"`
	CustomsInvoiceNr   *string             `json:"customs_invoice_nr,omitempty"`
	DeliveryOption     string              `json:"delivery_option,omitempty"`
	CustomsInformation *CustomsInformation `json:"customs_information,omitempty"`
	ApplyRules         *bool               `json:"apply_rules,omitempty"`
}

ReturnRequest is the JSON body structure for creating a returns.

type ReturnResponse added in v0.4.6

type ReturnResponse struct {
	ReturnID      int64   `json:"return_id"`
	ParcelID      int64   `json:"parcel_id"`
	MultiColloIDs []int64 `json:"multi_collo_ids"`
}

ReturnResponse represents the basic response from a create returns call.

func (*ReturnResponse) GetResponse added in v0.4.6

func (r *ReturnResponse) GetResponse() interface{}

GetResponse returns the unmarshaled ReturnResponse.

func (*ReturnResponse) SetResponse added in v0.4.6

func (r *ReturnResponse) SetResponse(body []byte) error

SetResponse unmarshals the API response into ReturnResponseContainer.

type Sender

type Sender struct {
	ID          int64
	CompanyName string
	Email       string
	PhoneNumber string
	Street      string
	HouseNumber string
	PostCode    string
	City        string
	CountryCode string
}

type SenderResponse

type SenderResponse struct {
	ID          int64  `json:"id"`
	CompanyName string `json:"company_name"`
	ContactName string `json:"contact_name"`
	Email       string `json:"email"`
	Telephone   string `json:"telephone"`
	Street      string `json:"street"`
	HouseNumber string `json:"house_number"`
	PostalBox   string `json:"postal_box"`
	PostalCode  string `json:"postal_code"`
	City        string `json:"city"`
	Country     string `json:"country"`
}

type SenderResponseContainer

type SenderResponseContainer struct {
	SenderAddresses []SenderResponse `json:"sender_addresses"`
}

func (*SenderResponseContainer) GetResponse

func (a *SenderResponseContainer) GetResponse() interface{}

Get formatted response

func (*SenderResponseContainer) SetResponse

func (a *SenderResponseContainer) SetResponse(body []byte) error

Set the response

type ServicePoint

type ServicePoint struct {
	ID                    int         `json:"id"`
	Code                  string      `json:"code"`
	IsActive              bool        `json:"is_active"`
	ExtraData             interface{} `json:"extra_data"`
	Name                  string      `json:"name"`
	Street                string      `json:"street"`
	HouseNumber           string      `json:"house_number"`
	PostalCode            string      `json:"postal_code"`
	City                  string      `json:"city"`
	Latitude              string      `json:"latitude"`
	Longitude             string      `json:"longitude"`
	Email                 string      `json:"email"`
	Phone                 string      `json:"phone"`
	Homepage              string      `json:"homepage"`
	Carrier               string      `json:"carrier"`
	Country               string      `json:"country"`
	FormattedOpeningTimes struct {
		Num0 []string `json:"0"`
		Num1 []string `json:"1"`
		Num2 []string `json:"2"`
		Num3 []string `json:"3"`
		Num4 []string `json:"4"`
		Num5 []string `json:"5"`
		Num6 []string `json:"6"`
	} `json:"formatted_opening_times"`
	OpenTomorrow bool `json:"open_tomorrow"`
}

func (*ServicePoint) Identifier

func (s *ServicePoint) Identifier() string

type ServicePointList

type ServicePointList []ServicePoint

func (ServicePointList) GetResponse

func (s ServicePointList) GetResponse() interface{}

func (*ServicePointList) SetResponse

func (s *ServicePointList) SetResponse(body []byte) error

type ShipWith added in v0.4.6

type ShipWith struct {
	Type                string                 `json:"type,omitempty"` // either "shipping_option_code" or "shipping_product_code"
	ShippingOptionCode  string                 `json:"shipping_option_code,omitempty"`
	ShippingProductCode string                 `json:"shipping_product_code,omitempty"`
	Functionalities     map[string]interface{} `json:"functionalities,omitempty"`
	Contract            int64                  `json:"contract,omitempty"`
}

ShipWith defines the shipping method to be used for a returns.

type Shipment

type Shipment struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

type ShippingOption added in v0.4.7

type ShippingOption struct {
	Code            string                          `json:"code,omitempty"`
	Carrier         *CarrierOption                  `json:"carrier,omitempty"`
	Product         *ShippingProduct                `json:"product,omitempty"`
	Functionalities *CarrierShippingFunctionalities `json:"functionalities,omitempty"` // Response struct for functionalities
	MaxDimensions   *ResponseDimension              `json:"max_dimensions,omitempty"`  // Response struct for dimensions
	Weight          *ShippingOptionWeightRange      `json:"weight,omitempty"`
	BilledWeight    *BilledWeight                   `json:"billed_weight,omitempty"`
	Contract        *Contract                       `json:"contract,omitempty"`
	Requirements    *Requirements                   `json:"requirements,omitempty"`
	Quotes          []*ShippingQuote                `json:"quotes"` // Can be null from API, unmarshals to nil slice
}

ShippingOption represents a single shipping option with its details, pricing, and functionalities.

type ShippingOptionWeightRange added in v0.4.7

type ShippingOptionWeightRange struct {
	Min *ResponseWeight `json:"min,omitempty"`
	Max *ResponseWeight `json:"max,omitempty"`
}

ShippingOptionWeightRange defines the minimum and maximum weight for a shipping option.

type ShippingPriceBreakdownItem added in v0.4.7

type ShippingPriceBreakdownItem struct {
	Type  string         `json:"type,omitempty"`
	Label string         `json:"label,omitempty"`
	Price *ResponsePrice `json:"price,omitempty"`
}

ShippingPriceBreakdownItem details a component of the shipping price.

type ShippingProduct added in v0.4.7

type ShippingProduct struct {
	Code string `json:"code,omitempty"`
	Name string `json:"name,omitempty"`
}

ShippingProduct represents product information for a shipping option.

type ShippingQuote added in v0.4.7

type ShippingQuote struct {
	Weight   QuoteWeightRange `json:"weight,omitempty"`
	LeadTime *int             `json:"lead_time,omitempty"` // API spec: integer or null
	Price    QuotePrice       `json:"price,omitempty"`
}

ShippingQuote provides pricing details for a shipping option within a specific weight range.

type Status

type Status struct {
	ID      int    `json:"id"`
	Message string `json:"message"`
}

type Weight added in v0.4.6

type Weight struct {
	Value float64 `json:"value"`
	Unit  string  `json:"unit"`
}

Weight specifies the weight.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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