jjideenschmiede / gosendcloud

Our library to use the sendcloud API endpoints in golang.

Home Page:https://docs.sendcloud.sc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gosendcloud

GitHub go.mod Go version of a Go module Go Go Report Card Go Doc Lines of code Developed with <3

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)
}

About

Our library to use the sendcloud API endpoints in golang.

https://docs.sendcloud.sc/

License:MIT License


Languages

Language:Go 100.0%