Coder Social home page Coder Social logo

iezed / goshopify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jjideenschmiede/goshopify

0.0 0.0 0.0 121 KB

An library to use the shopify rest api in go.

Home Page: https://shopify.dev/api/admin/rest/reference/

License: MIT License

Go 100.00%

goshopify's Introduction

goshopify

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

This library is currently far from finished. We will extend it when we need more endpoints for our projects. Feel free to add more endpoints as well.

Install

go get github.com/jjideenschmiede/goshopify

How to use?

Get a single product

If you want to read out an individual product directly via the Id, you can do this using this function. You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
	AccessToken: "",
}

// Get a product by id
product, err := goshopify.Product(6147990126757, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(product)
}

Add a product

With this function, you can add both simple and variant products. Here you can find an example of how to add a simple product. If it is to be a variant product, then variants are also added in the []ProductBodyVariants slice, but instead of using the Title option, another one such as size or color is used and the variants are assigned one of the values present in the option. It is important that the Id in the ProductBodyProduct struct is 0.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Define body
body := goshopify.ProductBody{
    goshopify.ProductBodyProduct{
    	Id:          0,
        Title:       "",
        BodyHtml:    "",
        Vendor:      "",
        ProductType: "",
        Status:      "",
        Tags:        "",
        Images:      []goshopify.ProductBodyImages{},
        Variants:    []goshopify.ProductBodyVariants{},
        Options:     []goshopify.ProductBodyOptions{},
    },
}

// Add new images
body.Product.Images = append(body.Product.Images, goshopify.ProductBodyImages{Src: ""})

// Add new variants
body.Product.Variants = append(body.Product.Variants, goshopify.ProductBodyVariants{
    Title:               "",
    Price:               "",
    Sku:                 "",
    CompareAtPrice       "",
    FulfillmentService:  "",
    InventoryManagement: "",
    Option1:             "Default Title",
    Option2:             "",
    Option3:             "",
    Taxable:             false,
    Barcode:             "",
    Grams:               0,
    Weight:              0,
    WeightUnit:          "",
    InventoryQuantity:   0,
    RequiresShipping:    false,
})

// Add new options
body.Product.Options = append(body.Product.Options, goshopify.ProductBodyOptions{
    Name:   "Title",
    Values: []string{"Default Title"},
})

// Add new product
product, err := goshopify.AddProduct(body, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(product)
}

Update a product

Updating a product is actually identical to creating a product. The important thing here is that the ID in the ProductBodyProduct struct is the ID of the product. So the whole product can be updated.

The only difference is that a different function must be called.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Add new product
updateProduct, err := goshopify.UpdateProduct(body, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(product)
}

Delete a product

If you want to remove a product, you can do this using the following function.

The ID of the product must also be specified. Please specify the request struct.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Delete product
err := goshopify.DeleteProduct(6881118224568, r)
if err != nil {
	fmt.Println(err)
}

Get a list of metafields for a product

If you want to read out all metafields of a product, you can do this as follows. You need the ID of the product.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Get all metafields of a product
metafields, err := goshopify.ProductMetafields(7305370009784, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(metafields)
}

Delete a metafield from a product

If you want to delete a metafield from a product, you can do so using the following function.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Delete a variant
err := goshopify.DeleteProductMetafield(7179007656120, 26048686751928, r)
if err != nil {
    fmt.Println(err)
}

Get a list of all product variants

If you want to read out all variants of a product, you can do this as follows. Only the ID of the main product is required for this.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Get all product variants
productVariants, err := goshopify.ProductVariants(6917353078968, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(productVariants)
}

Create a variant to a product

If you want to create a new variant, you can do so using the following function. The ID of the main product is required.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    ApiKey:      "",
    ApiPassword: "",
    StoreName:   "",
}

// Define body
body := ProductVariantBody{
    ProductVariantBodyVariant{
        Id:                  6917353078,
        Title:               "Testartikel",
        Price:               "24,99",
        Sku:                 "21481462121",
        CompareAtPrice:      "48,99",
        FulfillmentService:  "manual",
        InventoryManagement: "shopify",
        Option1:             "42",
        Option2:             "",
        Option3:             "",
        Taxable:             true,
        Barcode:             "",
        Grams:               0,
        Weight:              0,
        WeightUnit:          "",
        InventoryQuantity:   0,
        RequiresShipping:    true,
    },
}

// Create a product variant
variant, err := goshopify.AddProductVariant(6917353078968, body, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(variant)
}

Update a variant

If you want to renew an existing variant, this works similarly to creating a variant. But you use the id of the variant and not the id of the main product.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Define body
body := ProductVariantBody{
    ProductVariantBodyVariant{
        Id:                  6917353078968,
        Title:               "Testartikel",
        Price:               "24,99",
        Sku:                 "21481462121",
        CompareAtPrice:      "48,99",
        FulfillmentService:  "manual",
        InventoryManagement: "shopify",
        Option1:             "42",
        Option2:             "",
        Option3:             "",
        Taxable:             true,
        Barcode:             "",
        Grams:               0,
        Weight:              0,
        WeightUnit:          "",
        InventoryQuantity:   0,
        RequiresShipping:    true,
    },
}

// Create a product variant
variant, err := goshopify.AddProductVariant(body, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(variant)
}

Delete a variant

If you want to remove a variant from a product, you can do it as follows.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Delete a variant
err := goshopify.DeleteVariant(7179007656120, 41753091834040, r)
if err != nil {
    fmt.Println(err)
}

Get a list of metafields for a product variant

If you want to read out all metafields of a product variant, you can do this as follows.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Get all metafields of a product variant
metafields, err := goshopify.ProductVariantMetafields(7305370009784, 42407097598136, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(metafields)
}

Delete a metafield from a variant product

If you want to delete a metafield from a variant, you can do so using the following function. You need the ID of the main product and the ID of the variant.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Delete a variant
err := goshopify.DeleteProductVariantMetafield(7179007656120, 41753091834040, 26048686751928, r)
if err != nil {
    fmt.Println(err)
}

Get all inventory locations

If you want to read out all inventory locations, you can do this with the following function. You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Get all inventory locations
locations, err := goshopify.InventoryLocations(r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(locations)
}

Set an inventory level

If you want to customize a pass, you can do so as follows. For this you need the Inventory Id and the Location Id of the product. You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Define body
body := goshopify.InventoryLevelBody{
    LocationId:      62413209784,
    InventoryItemId: 42744167694520,
    Available:       24,
}

// Get all inventory locations
inventory, err := goshopify.InventoryLevels(body, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(inventory)
}

Get list of orders since id

To get a list of orders, you can call the following function. The list shows all orders by a certain ID, if you leave this ID at 0, then the orders are displayed from the beginning. 200 orders are always read out at once.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
	StoreName:   "",
    AccessToken: "",
}

// Get order list after id (200 items)
orders, err := goshopify.Orders(0, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(orders)
}

Get the last order

If you want to read the last placed order from Shopify, then you can do it as follows.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
	StoreName:   "",
    AccessToken: "",
}

// Get the last order
order, err := goshopify.Order(r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(order)
}

Get a list of transactions from an order

If you want to read all transactions from an order from Shopify, then you can do it as follows.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
	StoreName:   "",
    AccessToken: "",
}

// Get the last order
transactions, err := goshopify.OrderTransactions(4568137629880, r)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(transaction)
}

Add fulfillment to order

If the item has been shipped, the following function can be used to submit the tracking number, shipping provider and tracking link.

You can find the description from Shopify here.

// Define request
r := goshopify.Request{
    StoreName:   "",
    AccessToken: "",
}

// Define fulfillment body
body := FulfillmentBody{
    Fulfillment: FulfillmentBodyFulfillment{
        LocationId:      62413209784,
        TrackingNumber:  "123456789010",
        TrackingCompany: "fed ex",
        TrackingUrl:     "https://test.de/tracking/123456789010",
    },
}

// Add new fulfillment
fulfillment, err := AddFulfillment(4344802345144, body, r)
if err != nil {
    log.Fatalln(err)
} else {
    log.Println(fulfillment)
}

Help

For help or questions, please contact us directly here.

goshopify's People

Contributors

gowizzard 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.