diff --git a/README.md b/README.md index d95961d..b53dd75 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,24 @@ if err != nil { } ``` +## Delete a product image + +If you want to remove an image from a product, you can do so using the following function. You need the ID of the product and the ID of the image. + +```go +// Define request +r := goshopify.Request{ + StoreName: "", + AccessToken: "", +} + +// Delete product image +err := goshopify.DeleteProductImage(7384409964728, 43713916108984, 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. diff --git a/product_image.go b/product_image.go index c87429c..1c0ab19 100644 --- a/product_image.go +++ b/product_image.go @@ -15,6 +15,7 @@ type ProductImageBody struct { } type ProductImageBodyImage struct { + Id int `json:"id,omitempty"` Position int `json:"position,omitempty"` Src string `json:"src"` Alt string `json:"alt,omitempty"` @@ -71,3 +72,22 @@ func AddProductImage(id int, body ProductImageBody, r Request) (ProductImageRetu return decode, err } + +// DeleteProductImage is to delete an image of a product +func DeleteProductImage(productId, imageId int, r Request) error { + + // Set config for new request + c := Config{fmt.Sprintf("/products/%d/images/%d.json", productId, imageId), http.MethodDelete, nil} + + // Send request + response, err := c.Send(r) + if err != nil { + return err + } + + // Close request + defer response.Body.Close() + + // Return nothing + return nil +}