gosendcloud

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: MIT Imports: 6 Imported by: 0

README

gosendcloud

GitHub go.mod Go version of a Go module Go Go Report Card Go Doc Lines of code

With this library it should be possible to interact with the endpoints of the sendcloud API via golang functions. Since we can not implement this library project-specific completely, you are welcome to extend it with us.

Install

go get github.com/jjideenschmiede/gosendcloud

How to use?

Create a Parcel

If a new dispatch note is to be created, then this can be done directly with the following function. You can find more information about the structure of the request in the sendcloud documentation.

// Define request
r := gosendcloud.Request{
    PublicKey: "",
    SecretKey: "",
}

// Define request body
body := gosendcloud.CreateAParcelBody{
    Parcel: gosendcloud.CreateAParcelBodyParcel{
        Name:         "Jonas Kwiedor",
        CompanyName:  "J&J Ideenschmiede GmbH",
        Address:      "Mercatorstraße",
        HouseNumber:  "32a",
        City:         "Geesthacht",
        PostalCode:   "21502",
        Telephone:    "+4941528903730",
        RequestLabel: true,
        Email:        "info@jj-ideenschmiede.de",
        Country:      "DE",
        Shipment: gosendcloud.CreateAParcelBodyShipment{
            Id: 8,
        },
        Weight:                     "10.000",
        OrderNumber:                "41267142142",
        InsuredValue:               2000,
        TotalOrderValueCurrency:    "EUR",
        TotalOrderValue:            "24.99",
        Quantity:                   1,
        ShippingMethodCheckoutName: "DPD",
    },
}

// Create a new parcel
create, err := gosendcloud.CreateAParcel(body, r)
if err != nil {
    log.Fatalln(err)
} else {
    log.Println(create)
}
Inserting shipments into an integration

If you want to create an order via an integration, then you can do this as follows. You can find more information about the structure of the request in the sendcloud documentation.

// Define request
r := gosendcloud.Request{
    PublicKey: "",
    SecretKey: "",
}

// Define request body
var body []gosendcloud.InsertingShipmentsBody

body = append(body, gosendcloud.InsertingShipmentsBody{
    Address:             "Insulindelaan",
    Address2:            "",
    City:                "Eindhoven",
    CompanyName:         "Sendcloud",
    Country:             "NL",
    CreatedAt:           "2021-12-02T10:00:00.555309+00:00",
    Currency:            "EUR",
    CustomsInvoiceNr:    "",
    CustomsShipmentType: 2,
    Email:               "info@jj-development.de",
    ExternalOrderId:     "1234521226",
    ExternalShipmentId:  nil,
    HouseNumber:         "115",
    Name:                "Kwiedor",
    OrderNumber:         "414124124214214",
    OrderStatus: &gosendcloud.InsertingShipmentsBodyOrderStatus{
        Id:      "fulfilled",
        Message: "Fulfilled",
    },
    ParcelItems: []gosendcloud.InsertingShipmentsBodyParcelItems{},
    PaymentStatus: &gosendcloud.InsertingShipmentsBodyPaymentStatus{
        Id:      "paid",
        Message: "Paid",
    },
    PostalCode:                 "5642 CV",
    SenderAddress:              1,
    ShippingMethod:             111,
    ShippingMethodCheckoutName: "DPD Classic",
    Telephone:                  "+31612345678",
    ToPostNumber:               "",
    ToServicePoint:             nil,
    ToState:                    nil,
    TotalOrderValue:            "13.99",
    UpdatedAt:                  "2021-12-02T11:01:47.505309+00:00",
    Weight:                     "0.300",
    Width:                      "40.00",
    Height:                     "30.00",
    Length:                     "50.00",
    Shipments:                  nil,
    CheckoutPayload:            nil,
})

// Add a parcel item
body[0].ParcelItems = append(body[0].ParcelItems, gosendcloud.InsertingShipmentsBodyParcelItems{
    Description:   "T-Shirt",
    HsCode:        "",
    OriginCountry: "",
    ProductId:     "a_random_id",
    Properties:    map[string]interface{}{},
    Quantity:      2,
    Sku:           "a_random_sku",
    Value:         "300",
    Weight:        "0.300",
})

// Inserting a new shipment
insert, err := gosendcloud.InsertingShipments(198416, body, r)
if err != nil {
    log.Fatalln(err)
} else {
    log.Println(insert)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path, Method string
	Body         []byte
}

Config is to define config data

func (Config) Send

func (c Config) Send(r Request) (*http.Response, error)

Send is to send a new request

type CreateAParcelBody

type CreateAParcelBody struct {
	Parcel CreateAParcelBodyParcel `json:"parcel"`
}

CreateAParcelBody is to structure the json data

type CreateAParcelBodyParcel

type CreateAParcelBodyParcel struct {
	Name                       string                    `json:"name"`
	CompanyName                string                    `json:"company_name"`
	Address                    string                    `json:"address"`
	HouseNumber                string                    `json:"house_number"`
	City                       string                    `json:"city"`
	PostalCode                 string                    `json:"postal_code"`
	Telephone                  string                    `json:"telephone"`
	RequestLabel               bool                      `json:"request_label"`
	Email                      string                    `json:"email"`
	Data                       []interface{}             `json:"data,omitempty"`
	Country                    string                    `json:"country"`
	Shipment                   CreateAParcelBodyShipment `json:"shipment"`
	Weight                     string                    `json:"weight"`
	OrderNumber                string                    `json:"order_number"`
	InsuredValue               int                       `json:"insured_value"`
	TotalOrderValueCurrency    string                    `json:"total_order_value_currency"`
	TotalOrderValue            string                    `json:"total_order_value"`
	Quantity                   int                       `json:"quantity"`
	ShippingMethodCheckoutName string                    `json:"shipping_method_checkout_name"`
}

type CreateAParcelBodyShipment

type CreateAParcelBodyShipment struct {
	Id int `json:"id"`
}

type CreateAParcelReturn

type CreateAParcelReturn struct {
	Parcel struct {
		Id             int    `json:"id"`
		Address        string `json:"address"`
		Address2       string `json:"address_2"`
		AddressDivided struct {
			Street      string `json:"street"`
			HouseNumber string `json:"house_number"`
		} `json:"address_divided"`
		City        string `json:"city"`
		CompanyName string `json:"company_name"`
		Country     struct {
			Iso2 string `json:"iso_2"`
			Iso3 string `json:"iso_3"`
			Name string `json:"name"`
		} `json:"country"`
		Data struct {
		} `json:"data"`
		DateCreated   string `json:"date_created"`
		DateAnnounced string `json:"date_announced"`
		DateUpdated   string `json:"date_updated"`
		Email         string `json:"email"`
		Name          string `json:"name"`
		PostalCode    string `json:"postal_code"`
		Reference     string `json:"reference"`
		Shipment      struct {
			Id   int    `json:"id"`
			Name string `json:"name"`
		} `json:"shipment"`
		Status struct {
			Id      int    `json:"id"`
			Message string `json:"message"`
		} `json:"status"`
		ToServicePoint interface{} `json:"to_service_point"`
		Telephone      string      `json:"telephone"`
		TrackingNumber string      `json:"tracking_number"`
		Weight         string      `json:"weight"`
		Label          struct {
			NormalPrinter []string `json:"normal_printer"`
			LabelPrinter  string   `json:"label_printer"`
		} `json:"label"`
		CustomsDeclaration struct {
		} `json:"customs_declaration"`
		OrderNumber         string        `json:"order_number"`
		InsuredValue        int           `json:"insured_value"`
		TotalInsuredValue   int           `json:"total_insured_value"`
		ToState             interface{}   `json:"to_state"`
		CustomsInvoiceNr    string        `json:"customs_invoice_nr"`
		CustomsShipmentType interface{}   `json:"customs_shipment_type"`
		ParcelItems         []interface{} `json:"parcel_items"`
		Documents           []struct {
			Type string `json:"type"`
			Size string `json:"size"`
			Link string `json:"link"`
		} `json:"documents"`
		Type                       string      `json:"type"`
		ShipmentUuid               interface{} `json:"shipment_uuid"`
		ShippingMethod             int         `json:"shipping_method"`
		ExternalOrderId            string      `json:"external_order_id"`
		ExternalShipmentId         string      `json:"external_shipment_id"`
		ExternalReference          interface{} `json:"external_reference"`
		IsReturn                   bool        `json:"is_return"`
		Note                       string      `json:"note"`
		ToPostNumber               string      `json:"to_post_number"`
		TotalOrderValue            string      `json:"total_order_value"`
		TotalOrderValueCurrency    string      `json:"total_order_value_currency"`
		ColliTrackingNumber        string      `json:"colli_tracking_number"`
		ColliUuid                  string      `json:"colli_uuid"`
		ColloNr                    int         `json:"collo_nr"`
		ColloCount                 int         `json:"collo_count"`
		AwbTrackingNumber          interface{} `json:"awb_tracking_number"`
		BoxNumber                  interface{} `json:"box_number"`
		Length                     interface{} `json:"length"`
		Width                      interface{} `json:"width"`
		Height                     interface{} `json:"height"`
		ShippingMethodCheckoutName string      `json:"shipping_method_checkout_name"`
		Carrier                    struct {
			Code string `json:"code"`
		} `json:"carrier"`
		TrackingUrl string `json:"tracking_url"`
	} `json:"parcel"`
	Error struct {
		Code    int    `json:"code"`
		Request string `json:"request"`
		Message string `json:"message"`
	} `json:"error,omitempty"`
}

CreateAParcelReturn is to decode the json return

func CreateAParcel

func CreateAParcel(body CreateAParcelBody, r Request) (CreateAParcelReturn, error)

CreateAParcel is to create a new parcel

type InsertingShipmentsBody added in v1.0.4

type InsertingShipmentsBody struct {
	Address                    string                                 `json:"address"`
	Address2                   string                                 `json:"address_2"`
	City                       string                                 `json:"city"`
	CompanyName                string                                 `json:"company_name"`
	Country                    string                                 `json:"country"`
	CreatedAt                  string                                 `json:"created_at"`
	Currency                   string                                 `json:"currency"`
	CustomsInvoiceNr           string                                 `json:"customs_invoice_nr"`
	CustomsShipmentType        int                                    `json:"customs_shipment_type"`
	Email                      string                                 `json:"email"`
	ExternalOrderId            string                                 `json:"external_order_id"`
	ExternalShipmentId         *string                                `json:"external_shipment_id"`
	HouseNumber                string                                 `json:"house_number"`
	Name                       string                                 `json:"name"`
	OrderNumber                string                                 `json:"order_number"`
	OrderStatus                *InsertingShipmentsBodyOrderStatus     `json:"order_status"`
	ParcelItems                []InsertingShipmentsBodyParcelItems    `json:"parcel_items"`
	PaymentStatus              *InsertingShipmentsBodyPaymentStatus   `json:"payment_status"`
	PostalCode                 string                                 `json:"postal_code"`
	SenderAddress              int                                    `json:"sender_address,omitempty"`
	ShippingMethod             *int                                   `json:"shipping_method,omitempty"`
	ShippingMethodCheckoutName string                                 `json:"shipping_method_checkout_name"`
	Telephone                  string                                 `json:"telephone"`
	ToPostNumber               string                                 `json:"to_post_number"`
	ToServicePoint             interface{}                            `json:"to_service_point"`
	ToState                    interface{}                            `json:"to_state"`
	TotalOrderValue            string                                 `json:"total_order_value,omitempty"`
	UpdatedAt                  string                                 `json:"updated_at"`
	Weight                     string                                 `json:"weight"`
	Width                      string                                 `json:"width,omitempty"`
	Height                     string                                 `json:"height,omitempty"`
	Length                     string                                 `json:"length,omitempty"`
	Shipments                  []interface{}                          `json:"shipments,omitempty"`
	CheckoutPayload            *InsertingShipmentsBodyCheckoutPayload `json:"checkout_payload,omitempty"`
}

InsertingShipmentsBody is to structure the data

type InsertingShipmentsBodyCheckoutPayload added in v1.0.4

type InsertingShipmentsBodyCheckoutPayload struct {
	SenderAddressId    int                                      `json:"sender_address_id"`
	ShippingProduct    InsertingShipmentsBodyShippingProduct    `json:"shipping_product"`
	DeliveryMethodType string                                   `json:"delivery_method_type"`
	DeliveryMethodData InsertingShipmentsBodyDeliveryMethodData `json:"delivery_method_data"`
}

type InsertingShipmentsBodyDeliveryMethodData added in v1.0.4

type InsertingShipmentsBodyDeliveryMethodData struct {
	DeliveryDate          string `json:"delivery_date"`
	FormattedDeliveryDate string `json:"formatted_delivery_date"`
	ParcelHandoverDate    string `json:"parcel_handover_date"`
}

type InsertingShipmentsBodyOrderStatus added in v1.0.4

type InsertingShipmentsBodyOrderStatus struct {
	Id      string `json:"id"`
	Message string `json:"message"`
}

type InsertingShipmentsBodyParcelItems added in v1.0.4

type InsertingShipmentsBodyParcelItems struct {
	Description   string                 `json:"description"`
	HsCode        string                 `json:"hs_code"`
	OriginCountry string                 `json:"origin_country"`
	ProductId     string                 `json:"product_id"`
	Properties    map[string]interface{} `json:"properties"`
	Quantity      int                    `json:"quantity"`
	Sku           string                 `json:"sku"`
	Value         string                 `json:"value"`
	Weight        string                 `json:"weight"`
}

type InsertingShipmentsBodyPaymentStatus added in v1.0.4

type InsertingShipmentsBodyPaymentStatus struct {
	Id      string `json:"id"`
	Message string `json:"message"`
}

type InsertingShipmentsBodySelectedFunctionalities added in v1.0.4

type InsertingShipmentsBodySelectedFunctionalities struct {
	AgeCheck           int    `json:"age_check"`
	LastMile           string `json:"last_mile"`
	FirstMile          string `json:"first_mile"`
	Multicollo         bool   `json:"multicollo"`
	FormFactor         string `json:"form_factor"`
	ServiceArea        string `json:"service_area"`
	WeekendDelivery    string `json:"weekend_delivery"`
	DeliveryDeadline   string `json:"delivery_deadline"`
	DirectContractOnly bool   `json:"direct_contract_only"`
}

type InsertingShipmentsBodyShippingProduct added in v1.0.4

type InsertingShipmentsBodyShippingProduct struct {
	Code                    string                                        `json:"code"`
	Name                    string                                        `json:"name"`
	SelectedFunctionalities InsertingShipmentsBodySelectedFunctionalities `json:"selected_functionalities"`
}

type InsertingShipmentsIntegrationWebhookReturn added in v1.0.8

type InsertingShipmentsIntegrationWebhookReturn struct {
	Action        string `json:"action"`
	Timestamp     int64  `json:"timestamp"`
	PublicKey     string `json:"public_key"`
	SecretKey     string `json:"secret_key"`
	IntegrationId int    `json:"integration_id"`
	Integration   struct {
		Id                   int           `json:"id"`
		ShopName             string        `json:"shop_name"`
		ShopUrl              string        `json:"shop_url"`
		System               string        `json:"system"`
		FailingSince         interface{}   `json:"failing_since"`
		LastFetch            interface{}   `json:"last_fetch"`
		LastUpdatedAt        time.Time     `json:"last_updated_at"`
		ServicePointEnabled  bool          `json:"service_point_enabled"`
		ServicePointCarriers []interface{} `json:"service_point_carriers"`
		WebhookActive        bool          `json:"webhook_active"`
		WebhookUrl           string        `json:"webhook_url"`
	} `json:"integration"`
}

InsertingShipmentsIntegrationWebhookReturn is to decode the json data

type InsertingShipmentsParcelStatusWebhookReturn added in v1.0.8

type InsertingShipmentsParcelStatusWebhookReturn struct {
	Action string `json:"action"`
	Parcel struct {
		Id             int    `json:"id"`
		Address        string `json:"address"`
		Address2       string `json:"address_2"`
		AddressDivided struct {
			Street      string `json:"street"`
			HouseNumber string `json:"house_number"`
		} `json:"address_divided"`
		City        string `json:"city"`
		CompanyName string `json:"company_name"`
		Country     struct {
			Iso2 string `json:"iso_2"`
			Iso3 string `json:"iso_3"`
			Name string `json:"name"`
		} `json:"country"`
		Data struct {
		} `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    struct {
			Id   int    `json:"id"`
			Name string `json:"name"`
		} `json:"shipment"`
		Status struct {
			Id      int    `json:"id"`
			Message string `json:"message"`
		} `json:"status"`
		ToServicePoint interface{} `json:"to_service_point"`
		Telephone      string      `json:"telephone"`
		TrackingNumber string      `json:"tracking_number"`
		Weight         string      `json:"weight"`
		Label          struct {
			NormalPrinter []string `json:"normal_printer"`
			LabelPrinter  string   `json:"label_printer"`
		} `json:"label"`
		CustomsDeclaration struct {
		} `json:"customs_declaration"`
		OrderNumber         string      `json:"order_number"`
		InsuredValue        int         `json:"insured_value"`
		TotalInsuredValue   int         `json:"total_insured_value"`
		ToState             interface{} `json:"to_state"`
		CustomsInvoiceNr    string      `json:"customs_invoice_nr"`
		CustomsShipmentType interface{} `json:"customs_shipment_type"`
		ParcelItems         []struct {
			Description   string      `json:"description"`
			HsCode        string      `json:"hs_code"`
			ProductId     string      `json:"product_id"`
			Quantity      int         `json:"quantity"`
			Weight        string      `json:"weight"`
			Sku           string      `json:"sku"`
			ReturnReason  interface{} `json:"return_reason"`
			ReturnMessage interface{} `json:"return_message"`
			Value         string      `json:"value"`
			Properties    struct {
				Size  string `json:"Size"`
				Color string `json:"Color"`
				Cut   string `json:"Cut,omitempty"`
			} `json:"properties"`
		} `json:"parcel_items"`
		Documents []struct {
			Type string `json:"type"`
			Size string `json:"size"`
			Link string `json:"link"`
		} `json:"documents"`
		Type                       string      `json:"type"`
		ShipmentUuid               string      `json:"shipment_uuid"`
		ShippingMethod             int         `json:"shipping_method"`
		ShippingMethodCheckoutName interface{} `json:"shipping_method_checkout_name"`
		ExternalOrderId            string      `json:"external_order_id"`
		ExternalShipmentId         string      `json:"external_shipment_id"`
		ExternalReference          interface{} `json:"external_reference"`
		IsReturn                   bool        `json:"is_return"`
		Note                       interface{} `json:"note"`
		ToPostNumber               string      `json:"to_post_number"`
		TotalOrderValue            string      `json:"total_order_value"`
		TotalOrderValueCurrency    string      `json:"total_order_value_currency"`
		Carrier                    struct {
			Code                     string `json:"code"`
			Name                     string `json:"name"`
			ServicepointsCarrierCode string `json:"servicepoints_carrier_code"`
		} `json:"carrier"`
		TrackingUrl             string      `json:"tracking_url"`
		DateUpdated             string      `json:"date_updated"`
		DateAnnounced           string      `json:"date_announced"`
		ColliTrackingNumber     string      `json:"colli_tracking_number"`
		ColliUuid               string      `json:"colli_uuid"`
		ColloNr                 int         `json:"collo_nr"`
		ColloCount              int         `json:"collo_count"`
		AwbTrackingNumber       interface{} `json:"awb_tracking_number"`
		BoxNumber               interface{} `json:"box_number"`
		Length                  string      `json:"length"`
		Width                   string      `json:"width"`
		Height                  string      `json:"height"`
		TrackTraceNotifications bool        `json:"track_trace_notifications"`
		FromCountry             struct {
			Iso2 string `json:"iso_2"`
			Iso3 string `json:"iso_3"`
			Name string `json:"name"`
		} `json:"from_country"`
		FromPostalCode string `json:"from_postal_code"`
		Contract       struct {
			Type string `json:"type"`
		} `json:"contract"`
		DateShipped        interface{}   `json:"date_shipped"`
		HouseNumber        string        `json:"house_number"`
		SuppressedStatuses []interface{} `json:"suppressed_statuses"`
		ShouldSendFeedback bool          `json:"should_send_feedback"`
		Source             string        `json:"source"`
	} `json:"parcel"`
	Timestamp int64 `json:"timestamp"`
}

InsertingShipmentsParcelStatusWebhookReturn is to decode the json data

type InsertingShipmentsReturn added in v1.0.4

type InsertingShipmentsReturn struct {
	ExternalOrderId    string `json:"external_order_id"`
	ExternalShipmentId string `json:"external_shipment_id"`
	ShipmentUuid       string `json:"shipment_uuid,omitempty"`
	Status             string `json:"status"`
	Error              struct {
		Address []string `json:"address"`
	} `json:"error,omitempty"`
}

InsertingShipmentsReturn is to decode the json return

func InsertingShipments added in v1.0.4

func InsertingShipments(id int, body []InsertingShipmentsBody, r Request) ([]InsertingShipmentsReturn, error)

InsertingShipments is to insert a shipment into an api integration

type Request

type Request struct {
	PublicKey string
	SecretKey string
}

Request is to define the request data

Jump to

Keyboard shortcuts

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