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 ¶
- func NewRequest(ctx context.Context, method, uri string, payload Payload, ...) (*http.Request, error)
- func Request(method, uri string, payload Payload, apiKey, apiSecret string, r Response) error
- func ValidateResponse(response *http.Response) error
- type AddressDivided
- type Carrier
- type Country
- type CountryResponse
- type CreateParcelItemRequest
- type CreateParcelShipmentRequest
- type CustomsShipmentType
- type Document
- type DocumentFormat
- type Error
- type ErrorResponse
- type Integration
- type IntegrationListResponseContainer
- type IntegrationParams
- type IntegrationRequest
- type IntegrationResponseContainer
- type LabelData
- type LabelResponse
- type LabelResponseContainer
- type Method
- type MethodListResponseContainer
- type MethodResponse
- type MethodResponseContainer
- type Parcel
- type ParcelListResponseContainer
- type ParcelParams
- type ParcelRequest
- type ParcelRequestContainer
- type ParcelResponse
- type ParcelResponseContainer
- type Payload
- type Response
- type Sender
- type SenderResponse
- type SenderResponseContainer
- type ServicePoint
- type ServicePointList
- type Shipment
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
Request sends a request to Sendcloud with given method, path, payload and credentials.
func ValidateResponse ¶ added in v0.4.5
ValidateResponse validates a received response from Sendcloud. It is valid and returns nil when the status code is between 200 and 299.
Types ¶
type AddressDivided ¶
type CountryResponse ¶
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 CustomsShipmentType ¶ added in v0.4.0
type CustomsShipmentType int
const ( CustomsShipmentTypeGift CustomsShipmentType = iota CustomsShipmentTypeDocuments CustomsShipmentTypeCommercialGoods CustomsShipmentTypeCommercialSample CustomsShipmentTypeReturnedGoods )
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 ErrorResponse ¶
type Integration ¶
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 LabelResponse ¶
type LabelResponseContainer ¶
type LabelResponseContainer struct {
Label LabelResponse `json:"label"`
}
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 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"` 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 return it as a Parcel{}
func (*ParcelResponseContainer) SetResponse ¶
func (p *ParcelResponseContainer) SetResponse(body []byte) error
Set the response
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