Git Product home page Git Product logo

gosendcloud's Introduction

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:        "[email protected]",
        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:               "[email protected]",
    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)
}

gosendcloud's People

Contributors

gowizzard avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.