goshopify

package module
v0.0.0-...-d59d03e Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MIT Imports: 18 Imported by: 0

README

go-shopify

Another Shopify Api Library in Go.

Note: The library does not have implementations of all Shopify resources, but it is being used in production by Conversio and should be stable for usage. PRs for new resources and endpoints are welcome, or you can simply implement some yourself as-you-go. See the section "Using your own models" for more info.

Build Status codecov

Install

$ go get github.com/getconversio/go-shopify

Use

import "github.com/getconversio/go-shopify"

This gives you access to the goshopify package.

Oauth

If you don't have an access token yet, you can obtain one with the oauth flow. Something like this will work:

// Create an app somewhere.
app := goshopify.App{
    ApiKey: "abcd",
    ApiSecret: "efgh",
    RedirectUrl: "https://example.com/shopify/callback",
    Scope: "read_products,read_orders",
}

// Create an oauth-authorize url for the app and redirect to it.
// In some request handler, you probably want something like this:
func MyHandler(w http.ResponseWriter, r *http.Request) {
    shopName := r.URL.Query().Get("shop")
    authUrl := app.AuthorizeURL(shopName)
    http.Redirect(w, r, authUrl, http.StatusFound)
}

// Fetch a permanent access token in the callback
func MyCallbackHandler(w http.ResponseWriter, r *http.Request) {
    // Check that the callback signature is valid
    if !app.VerifyAuthorizationURL(r.URL) {
        http.Error(w, "Invalid Signature", http.StatusUnauthorized)
        return
    }

    query := r.URL.Query()
    shopName := query.Get("shop")
    code := query.Get("code")
    token, err := app.GetAccessToken(shopName, code)

    // Do something with the token, like store it in a DB.
}
Api calls with a token

With a permanent access token, you can make API calls like this:

// Create an app somewhere.
app := goshopify.App{
    ApiKey: "abcd",
    ApiSecret: "efgh",
    RedirectUrl: "https://example.com/shopify/callback",
    Scope: "read_products",
}

// Create a new API client
client := goshopify.NewClient(app, "shopname", "token")

// Fetch the number of products.
numProducts, err := client.Product.Count(nil)
Private App Auth

Private Shopify apps use basic authentication and do not require going through the OAuth flow. Here is an example:

// Create an app somewhere.
app := goshopify.App{
	ApiKey: "apikey",
	Password: "apipassword",
}

// Create a new API client (notice the token parameter is the empty string)
client := goshopify.NewClient(app, "shopname", "")

// Fetch the number of products.
numProducts, err := client.Product.Count(nil)
Query options

Most API functions take an options interface{} as parameter. You can use one from the library or create your own. For example, to fetch the number of products created after January 1, 2016, you can do:

// Create standard CountOptions
date := time.Date(2016, time.January, 1, 0, 0, 0, 0, time.UTC)
options := goshopify.CountOptions{createdAtMin: date}

// Use the options when calling the API.
numProducts, err := client.Product.Count(options)

The options are parsed with Google's go-querystring library so you can use custom options like this:

// Create custom options for the orders.
// Notice the `url:"status"` tag
options := struct {
    Status string `url:"status"`
}{"any"}

// Fetch the order count for orders with status="any"
orderCount, err := client.Order.Count(options)
Using your own models

Not all endpoints are implemented right now. In those case, feel free to implement them and make a PR, or you can create your own struct for the data and use NewRequest with the API client. This is how the existing endpoints are implemented.

For example, let's say you want to fetch webhooks. There's a helper function Get specifically for fetching stuff so this will work:

// Declare a model for the webhook
type Webhook struct {
    ID int         `json:"id"`
    Address string `json:"address"`
}

// Declare a model for the resource root.
type WebhooksResource struct {
    Webhooks []Webhook `json:"webhooks"`
}

func FetchWebhooks() ([]Webhook, error) {
    path := "admin/webhooks.json"
    resource := new(WebhooksResoure)
    client := goshopify.NewClient(app, "shopname", "token")

    // resource gets modified when calling Get
    err := client.Get(path, resource, nil)

    return resource.Webhooks, err
}
Webhooks verification

In order to be sure that a webhook is sent from ShopifyApi you could easily verify it with the VerifyWebhookRequest method.

For example:

func ValidateWebhook(httpRequest *http.Request) (bool) {
    shopifyApp := goshopify.App{ApiSecret: "ratz"}
    return shopifyApp.VerifyWebhookRequest(httpRequest)
}

Develop and test

There's nothing special to note about the tests except that if you have Docker and Compose installed, you can test like this:

$ docker-compose build dev
$ docker-compose run --rm dev

Testing the package is the default command for the dev container. To create a coverage profile:

$ docker-compose run --rm dev bash -c 'go test -coverprofile=coverage.out ./... && go tool cover -html coverage.out -o coverage.html'

Documentation

Overview

Package goshopify provides methods for making requests to Shopify's admin API.

Index

Constants

View Source
const (
	UserAgent = "goshopify/1.0.0"
)

Variables

This section is empty.

Functions

func CheckResponseError

func CheckResponseError(r *http.Response) error

func ShopBaseUrl

func ShopBaseUrl(name string) string

Return the Shop's base url.

func ShopFullName

func ShopFullName(name string) string

Return the full shop name, including .myshopify.com

func ShopShortName

func ShopShortName(name string) string

Return the short shop name, excluding .myshopify.com

Types

type Address

type Address struct {
	ID           int     `json:"id"`
	Address1     string  `json:"address1"`
	Address2     string  `json:"address2"`
	City         string  `json:"city"`
	Company      string  `json:"company"`
	Country      string  `json:"country"`
	CountryCode  string  `json:"country_code"`
	FirstName    string  `json:"first_name"`
	LastName     string  `json:"last_name"`
	Latitude     float64 `json:"latitude"`
	Longitude    float64 `json:"longitude"`
	Name         string  `json:"name"`
	Phone        string  `json:"phone"`
	Province     string  `json:"province"`
	ProvinceCode string  `json:"province_code"`
	Zip          string  `json:"zip"`
}

type App

type App struct {
	ApiKey      string
	ApiSecret   string
	RedirectUrl string
	Scope       string
	Password    string
}

App represents basic app settings such as Api key, secret, scope, and redirect url. See oauth.go for OAuth related helper functions.

func (App) AuthorizeUrl

func (app App) AuthorizeUrl(shopName string, state string) string

Returns a Shopify oauth authorization url for the given shopname and state.

State is a unique value that can be used to check the authenticity during a callback from Shopify.

func (App) GetAccessToken

func (app App) GetAccessToken(shopName string, code string) (string, error)

func (App) VerifyAuthorizationURL

func (app App) VerifyAuthorizationURL(u *url.URL) (bool, error)

Verifying URL callback parameters.

func (App) VerifyMessage

func (app App) VerifyMessage(message, messageMAC string) bool

Verify a message against a message HMAC

func (App) VerifyWebhookRequest

func (app App) VerifyWebhookRequest(httpRequest *http.Request) bool

Verifies a webhook http request, sent by Shopify. The body of the request is still readable after invoking the method.

type Asset

type Asset struct {
	Attachment  string     `json:"attachment"`
	ContentType string     `json:"content_type"`
	Key         string     `json:"key"`
	PublicURL   string     `json:"public_url"`
	Size        int        `json:"size"`
	SourceKey   string     `json:"source_key"`
	Src         string     `json:"src"`
	ThemeID     int        `json:"theme_id"`
	Value       string     `json:"value"`
	CreatedAt   *time.Time `json:"created_at"`
	UpdatedAt   *time.Time `json:"updated_at"`
}

Asset represents a Shopify asset

type AssetResource

type AssetResource struct {
	Asset *Asset `json:"asset"`
}

AssetResource is the result from the themes/x/assets.json?asset[key]= endpoint

type AssetService

type AssetService interface {
	List(int, interface{}) ([]Asset, error)
	Get(int, string) (*Asset, error)
	Update(int, Asset) (*Asset, error)
	Delete(int, string) error
}

AssetService is an interface for interfacing with the asset endpoints of the Shopify API. See: https://help.shopify.com/api/reference/asset

type AssetServiceOp

type AssetServiceOp struct {
	// contains filtered or unexported fields
}

AssetServiceOp handles communication with the asset related methods of the Shopify API.

func (*AssetServiceOp) Delete

func (s *AssetServiceOp) Delete(themeID int, key string) error

Delete an asset

func (*AssetServiceOp) Get

func (s *AssetServiceOp) Get(themeID int, key string) (*Asset, error)

Get an asset by key from the given theme

func (*AssetServiceOp) List

func (s *AssetServiceOp) List(themeID int, options interface{}) ([]Asset, error)

List the metadata for all assets in the given theme

func (*AssetServiceOp) Update

func (s *AssetServiceOp) Update(themeID int, asset Asset) (*Asset, error)

Update an asset

type AssetsResource

type AssetsResource struct {
	Assets []Asset `json:"assets"`
}

AssetsResource is the result from the themes/x/assets.json endpoint

type Client

type Client struct {
	// HTTP client used to communicate with the DO API.
	Client *http.Client

	// Services used for communicating with the API
	Product          ProductService
	CustomCollection CustomCollectionService
	SmartCollection  SmartCollectionService
	Customer         CustomerService
	Order            OrderService
	Shop             ShopService
	Webhook          WebhookService
	Variant          VariantService
	Image            ImageService
	Transaction      TransactionService
	Theme            ThemeService
	Asset            AssetService
	// contains filtered or unexported fields
}

Client manages communication with the Shopify API.

func NewClient

func NewClient(app App, shopName, token string) *Client

Returns a new Shopify API client with an already authenticated shopname and token.

func (*Client) Count

func (c *Client) Count(path string, options interface{}) (int, error)

func (*Client) CreateAndDo

func (c *Client) CreateAndDo(method, path string, data, options, resource interface{}) error

CreateAndDo performs a web request to Shopify with the given method (GET, POST, PUT, DELETE) and relative path (e.g. "/admin/orders.json"). The data, options and resource arguments are optional and only relevant in certain situations. If the data argument is non-nil, it will be used as the body of the request for POST and PUT requests. The options argument is used for specifying request options such as search parameters like created_at_min Any data returned from Shopify will be marshalled into resource argument.

func (*Client) Delete

func (c *Client) Delete(path string) error

Delete performs a DELETE request for the given path

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) error

Do sends an API request and populates the given interface with the parsed response. It does not make much sense to call Do without a prepared interface instance.

func (*Client) Get

func (c *Client) Get(path string, resource, options interface{}) error

Get performs a GET request for the given path and saves the result in the given resource.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body, options interface{}) (*http.Request, error)

Creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) Post

func (c *Client) Post(path string, data, resource interface{}) error

Post performs a POST request for the given path and saves the result in the given resource.

func (*Client) Put

func (c *Client) Put(path string, data, resource interface{}) error

Put performs a PUT request for the given path and saves the result in the given resource.

type ClientDetails

type ClientDetails struct {
	AcceptLanguage string `json:"accept_language"`
	BrowserHeight  int    `json:"browser_height"`
	BrowserIp      string `json:"browser_ip"`
	BrowserWidth   int    `json:"browser_width"`
	SessionHash    string `json:"session_hash"`
	UserAgent      string `json:"user_agent"`
}

type CountOptions

type CountOptions struct {
	CreatedAtMin time.Time `url:"created_at_min,omitempty"`
	CreatedAtMax time.Time `url:"created_at_max,omitempty"`
	UpdatedAtMin time.Time `url:"updated_at_min,omitempty"`
	UpdatedAtMax time.Time `url:"updated_at_max,omitempty"`
}

General count options that can be used for most collection counts.

type CustomCollection

type CustomCollection struct {
	ID             int        `json:"id"`
	Handle         string     `json:"handle"`
	Title          string     `json:"title"`
	UpdatedAt      *time.Time `json:"updated_at"`
	BodyHTML       string     `json:"body_html"`
	SortOrder      string     `json:"sort_order"`
	TemplateSuffix string     `json:"template_suffix"`
	Image          Image      `json:"image"`
	Published      bool       `json:"published"`
	PublishedAt    *time.Time `json:"published_at"`
	PublishedScope string     `json:"published_scope"`
}

CustomCollection represents a Shopify custom collection.

type CustomCollectionResource

type CustomCollectionResource struct {
	Collection *CustomCollection `json:"custom_collection"`
}

CustomCollectionResource represents the result form the custom_collections/X.json endpoint

type CustomCollectionService

type CustomCollectionService interface {
	List(interface{}) ([]CustomCollection, error)
	Count(interface{}) (int, error)
	Get(int, interface{}) (*CustomCollection, error)
	Create(CustomCollection) (*CustomCollection, error)
	Update(CustomCollection) (*CustomCollection, error)
	Delete(int) error
}

CustomCollectionService is an interface for interacting with the custom collection endpoints of the Shopify API. See https://help.shopify.com/api/reference/customcollection

type CustomCollectionServiceOp

type CustomCollectionServiceOp struct {
	// contains filtered or unexported fields
}

CustomCollectionServiceOp handles communication with the custom collection related methods of the Shopify API.

func (*CustomCollectionServiceOp) Count

func (s *CustomCollectionServiceOp) Count(options interface{}) (int, error)

Count custom collections

func (*CustomCollectionServiceOp) Create

Create a new custom collection See Image for the details of the Image creation for a collection.

func (*CustomCollectionServiceOp) Delete

func (s *CustomCollectionServiceOp) Delete(collectionID int) error

Delete an existing custom collection.

func (*CustomCollectionServiceOp) Get

func (s *CustomCollectionServiceOp) Get(collectionID int, options interface{}) (*CustomCollection, error)

Get individual custom collection

func (*CustomCollectionServiceOp) List

func (s *CustomCollectionServiceOp) List(options interface{}) ([]CustomCollection, error)

List custom collections

func (*CustomCollectionServiceOp) Update

Update an existing custom collection

type CustomCollectionsResource

type CustomCollectionsResource struct {
	Collections []CustomCollection `json:"custom_collections"`
}

CustomCollectionsResource represents the result from the custom_collections.json endpoint

type Customer

type Customer struct {
	ID                  int              `json:"id"`
	Email               string           `json:"email"`
	FirstName           string           `json:"first_name"`
	LastName            string           `json:"last_name"`
	State               string           `json:"state"`
	Note                string           `json:"note"`
	VerifiedEmail       bool             `json:"verified_email"`
	MultipassIdentifier string           `json:"multipass_identifier"`
	OrdersCount         int              `json:"orders_count"`
	TaxExempt           bool             `json:"tax_exempt"`
	TotalSpent          *decimal.Decimal `json:"total_spent"`
	Phone               string           `json:"phone"`
	Tags                string           `json:"tags"`
	LastOrderId         int              `json:"last_order_id"`
	AcceptsMarketing    bool             `json:"accepts_marketing"`
	CreatedAt           *time.Time       `json:"created_at"`
	UpdatedAt           *time.Time       `json:"updated_at"`
}

Customer represents a Shopify customer

type CustomerResource

type CustomerResource struct {
	Customer *Customer `json:"customer"`
}

Represents the result from the customers/X.json endpoint

type CustomerSearchOptions

type CustomerSearchOptions struct {
	Page   int    `url:"page,omitempty"`
	Limit  int    `url:"limit,omitempty"`
	Fields string `url:"fields,omitempty"`
	Order  string `url:"order,omitempty"`
	Query  string `url:"query,omitempty"`
}

Represents the options available when searching for a customer

type CustomerService

type CustomerService interface {
	List(interface{}) ([]Customer, error)
	Count(interface{}) (int, error)
	Get(int, interface{}) (*Customer, error)
	Search(interface{}) ([]Customer, error)
	Update(Customer) (*Customer, error)
}

CustomerService is an interface for interfacing with the customers endpoints of the Shopify API. See: https://help.shopify.com/api/reference/customer

type CustomerServiceOp

type CustomerServiceOp struct {
	// contains filtered or unexported fields
}

CustomerServiceOp handles communication with the product related methods of the Shopify API.

func (*CustomerServiceOp) Count

func (s *CustomerServiceOp) Count(options interface{}) (int, error)

Count customers

func (*CustomerServiceOp) Get

func (s *CustomerServiceOp) Get(customerID int, options interface{}) (*Customer, error)

Get customer

func (*CustomerServiceOp) List

func (s *CustomerServiceOp) List(options interface{}) ([]Customer, error)

List customers

func (*CustomerServiceOp) Search

func (s *CustomerServiceOp) Search(options interface{}) ([]Customer, error)

Search customers

func (*CustomerServiceOp) Update

func (s *CustomerServiceOp) Update(customer Customer) (*Customer, error)

Update an existing customer

type CustomersResource

type CustomersResource struct {
	Customers []Customer `json:"customers"`
}

Represents the result from the customers.json endpoint

type DiscountCode

type DiscountCode struct {
	Amount *decimal.Decimal `json:"amount"`
	Code   string           `json:"code"`
	Type   string           `json:"type"`
}

type Fulfillment

type Fulfillment struct {
	ID              int        `json:"id"`
	OrderID         int        `json:"order_id"`
	Status          string     `json:"status"`
	CreatedAt       *time.Time `json:"created_at"`
	Service         string     `json:"service"`
	UpdatedAt       *time.Time `json:"updated_at"`
	TrackingCompany string     `json:"tracking_company"`
	ShipmentStatus  string     `json:"shipment_status"`
	TrackingNumber  string     `json:"tracking_number"`
	TrackingNumbers []string   `json:"tracking_numbers"`
	TrackingUrl     string     `json:"tracking_url"`
	TrackingUrls    []string   `json:"tracking_urls"`
	Receipt         Receipt    `json:"receipt"`
	LineItems       []LineItem `json:"line_items"`
}

type Image

type Image struct {
	ID         int        `json:"id"`
	ProductID  int        `json:"product_id"`
	Position   int        `json:"position"`
	CreatedAt  *time.Time `json:"created_at"`
	UpdatedAt  *time.Time `json:"updated_at"`
	Width      int        `json:"width"`
	Height     int        `json:"height"`
	Src        string     `json:"src,omitempty"`
	Attachment string     `json:"attachment,omitempty"`
	Filename   string     `json:"filename,omitempty"`
	VariantIds []int      `json:"variant_ids"`
}

Image represents a Shopify product's image.

type ImageResource

type ImageResource struct {
	Image *Image `json:"image"`
}

ImageResource represents the result form the products/X/images/Y.json endpoint

type ImageService

type ImageService interface {
	List(int, interface{}) ([]Image, error)
	Count(int, interface{}) (int, error)
	Get(int, int, interface{}) (*Image, error)
	Create(int, Image) (*Image, error)
	Update(int, Image) (*Image, error)
	Delete(int, int) error
}

ImageService is an interface for interacting with the image endpoints of the Shopify API. See https://help.shopify.com/api/reference/product_image

type ImageServiceOp

type ImageServiceOp struct {
	// contains filtered or unexported fields
}

ImageServiceOp handles communication with the image related methods of the Shopify API.

func (*ImageServiceOp) Count

func (s *ImageServiceOp) Count(productID int, options interface{}) (int, error)

Count images

func (*ImageServiceOp) Create

func (s *ImageServiceOp) Create(productID int, image Image) (*Image, error)

Create a new image

There are 2 methods of creating an image in Shopify: 1. Src 2. Filename and Attachment

If both Image.Filename and Image.Attachment are supplied, then Image.Src is not needed. And vice versa.

If both Image.Attachment and Image.Src are provided, Shopify will take the attachment.

Shopify will accept Image.Attachment without Image.Filename.

func (*ImageServiceOp) Delete

func (s *ImageServiceOp) Delete(productID int, imageID int) error

Delete an existing image

func (*ImageServiceOp) Get

func (s *ImageServiceOp) Get(productID int, imageID int, options interface{}) (*Image, error)

Get individual image

func (*ImageServiceOp) List

func (s *ImageServiceOp) List(productID int, options interface{}) ([]Image, error)

List images

func (*ImageServiceOp) Update

func (s *ImageServiceOp) Update(productID int, image Image) (*Image, error)

Update an existing image

type ImagesResource

type ImagesResource struct {
	Images []Image `json:"images"`
}

ImagesResource represents the result from the products/X/images.json endpoint

type LineItem

type LineItem struct {
	ID                         int              `json:"id"`
	ProductID                  int              `json:"product_id"`
	VariantID                  int              `json:"variant_id"`
	Quantity                   int              `json:"quantity"`
	Price                      *decimal.Decimal `json:"price"`
	TotalDiscount              *decimal.Decimal `json:"total_discount"`
	Title                      string           `json:"title"`
	VariantTitle               string           `json:"variant_title"`
	Name                       string           `json:"name"`
	SKU                        string           `json:"sku"`
	Vendor                     string           `json:"vendor"`
	GiftCard                   bool             `json:"gift_card"`
	Taxable                    bool             `json:"taxable"`
	FulfillmentService         string           `json:"fulfillment_service"`
	RequiresShipping           bool             `json:"requires_shipping"`
	VariantInventoryManagement string           `json:"variant_inventory_management"`
	Properties                 []NoteAttribute  `json:"properties"`
	ProductExists              bool             `json:"product_exists"`
	FulfillableQuantity        int              `json:"fulfillable_quantity"`
	Grams                      int              `json:"grams"`
	FulfillmentStatus          string           `json:"fulfillment_status"`
	TaxLines                   []TaxLine        `json:"tax_lines"`
	OriginLocation             *Address         `json:"origin_location"`
	DestinationLocation        *Address         `json:"destination_location"`
}

type LineItemProperty

type LineItemProperty struct {
	Message string `json:"message"`
}

type ListOptions

type ListOptions struct {
	Page         int       `url:"page,omitempty"`
	Limit        int       `url:"limit,omitempty"`
	SinceID      int       `url:"since_id,omitempty"`
	CreatedAtMin time.Time `url:"created_at_min,omitempty"`
	CreatedAtMax time.Time `url:"created_at_max,omitempty"`
	UpdatedAtMin time.Time `url:"updated_at_min,omitempty"`
	UpdatedAtMax time.Time `url:"updated_at_max,omitempty"`
	Order        string    `url:"order,omitempty"`
	Fields       string    `url:"fields,omitempty"`
}

General list options that can be used for most collections of entities.

type NoteAttribute

type NoteAttribute struct {
	Name  string      `json:"Name"`
	Value interface{} `json:"Value"`
}

type Order

type Order struct {
	ID                    int              `json:"id"`
	Name                  string           `json:"name"`
	Email                 string           `json:"email"`
	CreatedAt             *time.Time       `json:"created_at"`
	UpdatedAt             *time.Time       `json:"updated_at"`
	CancelledAt           *time.Time       `json:"cancelled_at"`
	ClosedAt              *time.Time       `json:"closed_at"`
	ProcessedAt           *time.Time       `json:"processed_at"`
	Customer              *Customer        `json:"customer"`
	BillingAddress        *Address         `json:"billing_address"`
	ShippingAddress       *Address         `json:"shipping_address"`
	Currency              string           `json:"currency"`
	TotalPrice            *decimal.Decimal `json:"total_price"`
	SubtotalPrice         *decimal.Decimal `json:"subtotal_price"`
	TotalDiscounts        *decimal.Decimal `json:"total_discounts"`
	TotalLineItemsPrice   *decimal.Decimal `json:"total_line_items_price"`
	TaxesIncluded         bool             `json:"taxes_included"`
	TotalTax              *decimal.Decimal `json:"total_tax"`
	TaxLines              []TaxLine        `json:"tax_lines"`
	TotalWeight           int              `json:"total_weight"`
	FinancialStatus       string           `json:"financial_status"`
	Fulfillments          []Fulfillment    `json:"fulfillments"`
	FulfillmentStatus     string           `json:"fulfillment_status"`
	Token                 string           `json:"token"`
	CartToken             string           `json:"cart_token"`
	Number                int              `json:"number"`
	OrderNumber           int              `json:"order_number"`
	Note                  string           `json:"note"`
	Test                  bool             `json:"test"`
	BrowserIp             string           `json:"browser_ip"`
	BuyerAcceptsMarketing bool             `json:"buyer_accepts_marketing"`
	CancelReason          string           `json:"cancel_reason"`
	NoteAttributes        []NoteAttribute  `json:"note_attributes"`
	DiscountCodes         []DiscountCode   `json:"discount_codes"`
	LineItems             []LineItem       `json:"line_items"`
	ShippingLines         []ShippingLines  `json:"shipping_lines"`
	Transactions          []Transaction    `json:"transactions"`
	AppID                 int              `json:"app_id"`
	CustomerLocale        string           `json:"customer_locale"`
	LandingSite           string           `json:"landing_site"`
	ReferringSite         string           `json:"referring_site"`
	SourceName            string           `json:"source_name"`
	ClientDetails         *ClientDetails   `json:"client_details"`
	Tags                  string           `json:"tags"`
	LocationId            int              `json:"location_id"`
	PaymentGatewayNames   []string         `json:"payment_gateway_names"`
	ProcessingMethod      string           `json:"processing_method"`
	Refunds               []Refund         `json:"refunds"`
	UserId                int              `json:"user_id"`
	OrderStatusUrl        string           `json:"order_status_url"`
}

Order represents a Shopify order

type OrderListOptions

type OrderListOptions struct {
	Page              int       `url:"page,omitempty"`
	Limit             int       `url:"limit,omitempty"`
	SinceID           int       `url:"since_id,omitempty"`
	Status            string    `url:"status,omitempty"`
	FinancialStatus   string    `url:"financial_status,omitempty"`
	FulfillmentStatus string    `url:"fulfillment_status,omitempty"`
	CreatedAtMin      time.Time `url:"created_at_min,omitempty"`
	CreatedAtMax      time.Time `url:"created_at_max,omitempty"`
	UpdatedAtMin      time.Time `url:"updated_at_min,omitempty"`
	UpdatedAtMax      time.Time `url:"updated_at_max,omitempty"`
	ProcessedAtMin    time.Time `url:"processed_at_min,omitempty"`
	ProcessedAtMax    time.Time `url:"processed_at_max,omitempty"`
	Fields            string    `url:"fields,omitempty"`
	Order             string    `url:"order,omitempty"`
}

A struct for all available order list options. See: https://help.shopify.com/api/reference/order#index

type OrderResource

type OrderResource struct {
	Order *Order `json:"order"`
}

Represents the result from the orders/X.json endpoint

type OrderService

type OrderService interface {
	List(interface{}) ([]Order, error)
	Count(interface{}) (int, error)
	Get(int, interface{}) (*Order, error)
}

OrderService is an interface for interfacing with the orders endpoints of the Shopify API. See: https://help.shopify.com/api/reference/order

type OrderServiceOp

type OrderServiceOp struct {
	// contains filtered or unexported fields
}

OrderServiceOp handles communication with the order related methods of the Shopify API.

func (*OrderServiceOp) Count

func (s *OrderServiceOp) Count(options interface{}) (int, error)

Count orders

func (*OrderServiceOp) Get

func (s *OrderServiceOp) Get(orderID int, options interface{}) (*Order, error)

Get individual order

func (*OrderServiceOp) List

func (s *OrderServiceOp) List(options interface{}) ([]Order, error)

List orders

type OrdersResource

type OrdersResource struct {
	Orders []Order `json:"orders"`
}

Represents the result from the orders.json endpoint

type PaymentDetails

type PaymentDetails struct {
	AVSResultCode     string `json:"avs_result_code"`
	CreditCardBin     string `json:"credit_card_bin"`
	CVVResultCode     string `json:"cvv_result_code"`
	CreditCardNumber  string `json:"credit_card_number"`
	CreditCardCompany string `json:"credit_card_company"`
}

type Product

type Product struct {
	ID                             int             `json:"id"`
	Title                          string          `json:"title"`
	BodyHTML                       string          `json:"body_html"`
	Vendor                         string          `json:"vendor"`
	ProductType                    string          `json:"product_type"`
	Handle                         string          `json:"handle"`
	CreatedAt                      *time.Time      `json:"created_at"`
	UpdatedAt                      *time.Time      `json:"updated_at"`
	PublishedAt                    *time.Time      `json:"published_at"`
	PublishedScope                 string          `json:"published_scope"`
	Tags                           string          `json:"tags"`
	Options                        []ProductOption `json:"options"`
	Variants                       []Variant       `json:"variants"`
	Image                          Image           `json:"image"`
	Images                         []Image         `json:"images"`
	TemplateSuffix                 string          `json:"template_suffix"`
	MetafieldsGlobalTitleTag       string          `json:"metafields_global_title_tag"`
	MetafieldsGlobalDescriptionTag string          `json:"metafields_global_description_tag"`
}

Product represents a Shopify product

type ProductOption

type ProductOption struct {
	ID        int      `json:"id"`
	ProductID int      `json:"product_id"`
	Name      string   `json:"name"`
	Position  int      `json:"position"`
	Values    []string `json:"values"`
}

The options provided by Shopify

type ProductResource

type ProductResource struct {
	Product *Product `json:"product"`
}

Represents the result from the products/X.json endpoint

type ProductService

type ProductService interface {
	List(interface{}) ([]Product, error)
	Count(interface{}) (int, error)
	Get(int, interface{}) (*Product, error)
	Create(Product) (*Product, error)
	Update(Product) (*Product, error)
	Delete(int) error
}

ProductService is an interface for interfacing with the product endpoints of the Shopify API. See: https://help.shopify.com/api/reference/product

type ProductServiceOp

type ProductServiceOp struct {
	// contains filtered or unexported fields
}

ProductServiceOp handles communication with the product related methods of the Shopify API.

func (*ProductServiceOp) Count

func (s *ProductServiceOp) Count(options interface{}) (int, error)

Count products

func (*ProductServiceOp) Create

func (s *ProductServiceOp) Create(product Product) (*Product, error)

Create a new product

func (*ProductServiceOp) Delete

func (s *ProductServiceOp) Delete(productID int) error

Delete an existing product

func (*ProductServiceOp) Get

func (s *ProductServiceOp) Get(productID int, options interface{}) (*Product, error)

Get individual product

func (*ProductServiceOp) List

func (s *ProductServiceOp) List(options interface{}) ([]Product, error)

List products

func (*ProductServiceOp) Update

func (s *ProductServiceOp) Update(product Product) (*Product, error)

Update an existing product

type ProductsResource

type ProductsResource struct {
	Products []Product `json:"products"`
}

Represents the result from the products.json endpoint

type RateLimitError

type RateLimitError struct {
	ResponseError
	RetryAfter int
}

An error specific to a rate-limiting response. Embeds the ResponseError to allow consumers to handle it the same was a normal ResponseError.

type Receipt

type Receipt struct {
	TestCase      bool   `json:"testcase"`
	Authorization string `json:"authorization"`
}

type Refund

type Refund struct {
	Id              int              `json:"id"`
	OrderId         int              `json:"order_id"`
	CreatedAt       *time.Time       `json:"created_at"`
	Note            string           `json:"note"`
	Restock         bool             `json:"restock"`
	UserId          int              `json:"user_id"`
	RefundLineItems []RefundLineItem `json:"refund_line_items"`
	Transactions    []Transaction    `json:"transactions"`
}

type RefundLineItem

type RefundLineItem struct {
	Id         int       `json:"id"`
	Quantity   int       `json:"quantity"`
	LineItemId int       `json:"line_item_id"`
	LineItem   *LineItem `json:"line_item"`
}

type ResponseError

type ResponseError struct {
	Status  int
	Message string
	Errors  []string
}

A general response error that follows a similar layout to Shopify's response errors, i.e. either a single message or a list of messages.

func (ResponseError) Error

func (e ResponseError) Error() string

type Rule

type Rule struct {
	Column    string `json:"column"`
	Relation  string `json:"relation"`
	Condition string `json:"condition"`
}

type ShippingLines

type ShippingLines struct {
	ID                            int              `json:"id"`
	Title                         string           `json:"title"`
	Price                         *decimal.Decimal `json:"price"`
	Code                          string           `json:"code"`
	Source                        string           `json:"source"`
	Phone                         string           `json:"phone"`
	RequestedFulfillmentServiceID string           `json:"requested_fulfillment_service_id"`
	DeliveryCategory              string           `json:"delivery_category"`
	CarrierIdentifier             string           `json:"carrier_identifier"`
	TaxLines                      []TaxLine        `json:"tax_lines"`
}

type Shop

type Shop struct {
	ID                      int        `json:"id"`
	Name                    string     `json:"name"`
	ShopOwner               string     `json:"shop_owner"`
	Email                   string     `json:"email"`
	CustomerEmail           string     `json:"customer_email"`
	CreatedAt               *time.Time `json:"created_at"`
	UpdatedAt               *time.Time `json:"updated_at"`
	Address1                string     `json:"address1"`
	Address2                string     `json:"address2"`
	City                    string     `json:"city"`
	Country                 string     `json:"country"`
	CountryCode             string     `json:"country_code"`
	CountryName             string     `json:"country_name"`
	Currency                string     `json:"currency"`
	Domain                  string     `json:"domain"`
	Latitude                float64    `json:"latitude"`
	Longitude               float64    `json:"longitude"`
	Phone                   string     `json:"phone"`
	Province                string     `json:"province"`
	ProvinceCode            string     `json:"province_code"`
	Zip                     string     `json:"zip"`
	MoneyFormat             string     `json:"money_format"`
	MoneyWithCurrencyFormat string     `json:"money_with_currency_format"`
	WeightUnit              string     `json:"weight_unit"`
	MyshopifyDomain         string     `json:"myshopify_domain"`
	PlanName                string     `json:"plan_name"`
	PlanDisplayName         string     `json:"plan_display_name"`
	PasswordEnabled         bool       `json:"password_enabled"`
	PrimaryLocale           string     `json:"primary_locale"`
	Timezone                string     `json:"timezone"`
	IanaTimezone            string     `json:"iana_timezone"`
	ForceSSL                bool       `json:"force_ssl"`
	TaxShipping             bool       `json:"tax_shipping"`
	TaxesIncluded           bool       `json:"taxes_included"`
	HasStorefront           bool       `json:"has_storefront"`
	HasDiscounts            bool       `json:"has_discounts"`
	HasGiftcards            bool       `json:"has_gift_cards"`
	SetupRequire            bool       `json:"setup_required"`
	CountyTaxes             bool       `json:"county_taxes"`
	CheckoutAPISupported    bool       `json:"checkout_api_supported"`
}

Shop represents a Shopify shop

type ShopResource

type ShopResource struct {
	Shop *Shop `json:"shop"`
}

Represents the result from the admin/shop.json endpoint

type ShopService

type ShopService interface {
	Get(options interface{}) (*Shop, error)
}

ShopService is an interface for interfacing with the shop endpoint of the Shopify API. See: https://help.shopify.com/api/reference/shop

type ShopServiceOp

type ShopServiceOp struct {
	// contains filtered or unexported fields
}

ShopServiceOp handles communication with the shop related methods of the Shopify API.

func (*ShopServiceOp) Get

func (s *ShopServiceOp) Get(options interface{}) (*Shop, error)

Get shop

type SmartCollection

type SmartCollection struct {
	ID             int        `json:"id"`
	Handle         string     `json:"handle"`
	Title          string     `json:"title"`
	UpdatedAt      *time.Time `json:"updated_at"`
	BodyHTML       string     `json:"body_html"`
	SortOrder      string     `json:"sort_order"`
	TemplateSuffix string     `json:"template_suffix"`
	Image          Image      `json:"image"`
	Published      bool       `json:"published"`
	PublishedAt    *time.Time `json:"published_at"`
	PublishedScope string     `json:"published_scope"`
	Rules          []Rule     `json:"rules"`
	Disjunctive    bool       `json:"disjunctive"`
}

SmartCollection represents a Shopify smart collection.

type SmartCollectionResource

type SmartCollectionResource struct {
	Collection *SmartCollection `json:"smart_collection"`
}

SmartCollectionResource represents the result form the smart_collections/X.json endpoint

type SmartCollectionService

type SmartCollectionService interface {
	List(interface{}) ([]SmartCollection, error)
	Count(interface{}) (int, error)
	Get(int, interface{}) (*SmartCollection, error)
	Create(SmartCollection) (*SmartCollection, error)
	Update(SmartCollection) (*SmartCollection, error)
	Delete(int) error
}

SmartCollectionService is an interface for interacting with the smart collection endpoints of the Shopify API. See https://help.shopify.com/api/reference/smartcollection

type SmartCollectionServiceOp

type SmartCollectionServiceOp struct {
	// contains filtered or unexported fields
}

SmartCollectionServiceOp handles communication with the smart collection related methods of the Shopify API.

func (*SmartCollectionServiceOp) Count

func (s *SmartCollectionServiceOp) Count(options interface{}) (int, error)

Count smart collections

func (*SmartCollectionServiceOp) Create

Create a new smart collection See Image for the details of the Image creation for a collection.

func (*SmartCollectionServiceOp) Delete

func (s *SmartCollectionServiceOp) Delete(collectionID int) error

Delete an existing smart collection.

func (*SmartCollectionServiceOp) Get

func (s *SmartCollectionServiceOp) Get(collectionID int, options interface{}) (*SmartCollection, error)

Get individual smart collection

func (*SmartCollectionServiceOp) List

func (s *SmartCollectionServiceOp) List(options interface{}) ([]SmartCollection, error)

List smart collections

func (*SmartCollectionServiceOp) Update

Update an existing smart collection

type SmartCollectionsResource

type SmartCollectionsResource struct {
	Collections []SmartCollection `json:"smart_collections"`
}

SmartCollectionsResource represents the result from the smart_collections.json endpoint

type TaxLine

type TaxLine struct {
	Title string           `json:"title"`
	Price *decimal.Decimal `json:"price"`
	Rate  *decimal.Decimal `json:"rate"`
}

type Theme

type Theme struct {
	ID           int        `json:"id"`
	Name         string     `json:"string"`
	Previewable  bool       `json:"previewable"`
	Processing   bool       `json:"processing"`
	Role         string     `json:"role"`
	ThemeStoreID int        `json:"theme_store_id"`
	CreatedAt    *time.Time `json:"created_at"`
	UpdatedAt    *time.Time `json:"updated_at"`
}

Theme represents a Shopify theme

type ThemeListOptions

type ThemeListOptions struct {
	ListOptions
	Role string `url:"role,omitempty"`
}

Options for theme list

type ThemeService

type ThemeService interface {
	List(interface{}) ([]Theme, error)
}

ThemeService is an interface for interfacing with the themes endpoints of the Shopify API. See: https://help.shopify.com/api/reference/theme

type ThemeServiceOp

type ThemeServiceOp struct {
	// contains filtered or unexported fields
}

ThemeServiceOp handles communication with the theme related methods of the Shopify API.

func (*ThemeServiceOp) List

func (s *ThemeServiceOp) List(options interface{}) ([]Theme, error)

List all themes

type ThemesResource

type ThemesResource struct {
	Themes []Theme `json:"themes"`
}

ThemesResource is the result from the themes.json endpoint

type Transaction

type Transaction struct {
	ID             int              `json:"id"`
	OrderID        int              `json:"order_id"`
	Amount         *decimal.Decimal `json:"amount"`
	Kind           string           `json:"kind"`
	Gateway        string           `json:"gateway"`
	Status         string           `json:"status"`
	Message        string           `json:"message"`
	CreatedAt      *time.Time       `json:"created_at"`
	Test           bool             `json:"test"`
	Authorization  string           `json:"authorization"`
	Currency       string           `json:"currency"`
	LocationID     *int             `json:"location_id"`
	UserID         *int             `json:"user_id"`
	ParentID       *int             `json:"parent_id"`
	DeviceID       *int             `json:"device_id"`
	ErrorCode      string           `json:"error_code"`
	SourceName     string           `json:"source_name"`
	PaymentDetails *PaymentDetails  `json:"payment_details"`
}

type TransactionResource

type TransactionResource struct {
	Transaction *Transaction `json:"transaction"`
}

TransactionResource represents the result from the orders/X/transactions/Y.json endpoint

type TransactionService

type TransactionService interface {
	List(int, interface{}) ([]Transaction, error)
	Count(int, interface{}) (int, error)
	Get(int, int, interface{}) (*Transaction, error)
	Create(int, Transaction) (*Transaction, error)
}

TransactionService is an interface for interfacing with the transactions endpoints of the Shopify API. See: https://help.shopify.com/api/reference/transaction

type TransactionServiceOp

type TransactionServiceOp struct {
	// contains filtered or unexported fields
}

TransactionServiceOp handles communication with the transaction related methods of the Shopify API.

func (*TransactionServiceOp) Count

func (s *TransactionServiceOp) Count(orderID int, options interface{}) (int, error)

Count transactions

func (*TransactionServiceOp) Create

func (s *TransactionServiceOp) Create(orderID int, transaction Transaction) (*Transaction, error)

Create a new transaction

func (*TransactionServiceOp) Get

func (s *TransactionServiceOp) Get(orderID int, transactionID int, options interface{}) (*Transaction, error)

Get individual transaction

func (*TransactionServiceOp) List

func (s *TransactionServiceOp) List(orderID int, options interface{}) ([]Transaction, error)

List transactions

type TransactionsResource

type TransactionsResource struct {
	Transactions []Transaction `json:"transactions"`
}

TransactionsResource represents the result from the orders/X/transactions.json endpoint

type Variant

type Variant struct {
	ID                   int              `json:"id"`
	ProductID            int              `json:"product_id"`
	Title                string           `json:"title"`
	Sku                  string           `json:"sku"`
	Position             int              `json:"position"`
	Grams                int              `json:"grams"`
	InventoryPolicy      string           `json:"inventory_policy"`
	Price                *decimal.Decimal `json:"price"`
	CompareAtPrice       *decimal.Decimal `json:"compare_at_price"`
	FulfillmentService   string           `json:"fulfillment_service"`
	InventoryManagement  string           `json:"inventory_management"`
	Option1              string           `json:"option1"`
	Option2              string           `json:"option2"`
	Option3              string           `json:"option3"`
	CreatedAt            *time.Time       `json:"created_at"`
	UpdatedAt            *time.Time       `json:"updated_at"`
	Taxable              bool             `json:"taxable"`
	Barcode              string           `json:"barcode"`
	ImageID              int              `json:"image_id"`
	InventoryQuantity    int              `json:"inventory_quantity"`
	Weight               *decimal.Decimal `json:"weight"`
	WeightUnit           string           `json:"weight_unit"`
	OldInventoryQuantity int              `json:"old_inventory_quantity"`
	RequireShipping      bool             `json:"requires_shipping"`
}

Variant represents a Shopify variant

type VariantResource

type VariantResource struct {
	Variant *Variant `json:"variant"`
}

VariantResource represents the result from the variants/X.json endpoint

type VariantService

type VariantService interface {
	List(int, interface{}) ([]Variant, error)
	Count(int, interface{}) (int, error)
	Get(int, interface{}) (*Variant, error)
	Create(int, Variant) (*Variant, error)
	Update(Variant) (*Variant, error)
	Delete(int, int) error
}

VariantService is an interface for interacting with the variant endpoints of the Shopify API. See https://help.shopify.com/api/reference/product_variant

type VariantServiceOp

type VariantServiceOp struct {
	// contains filtered or unexported fields
}

VariantServiceOp handles communication with the variant related methods of the Shopify API.

func (*VariantServiceOp) Count

func (s *VariantServiceOp) Count(productID int, options interface{}) (int, error)

Count variants

func (*VariantServiceOp) Create

func (s *VariantServiceOp) Create(productID int, variant Variant) (*Variant, error)

Create a new variant

func (*VariantServiceOp) Delete

func (s *VariantServiceOp) Delete(productID int, variantID int) error

Delete an existing product

func (*VariantServiceOp) Get

func (s *VariantServiceOp) Get(variantID int, options interface{}) (*Variant, error)

Get individual variant

func (*VariantServiceOp) List

func (s *VariantServiceOp) List(productID int, options interface{}) ([]Variant, error)

List variants

func (*VariantServiceOp) Update

func (s *VariantServiceOp) Update(variant Variant) (*Variant, error)

Update existing variant

type VariantsResource

type VariantsResource struct {
	Variants []Variant `json:"variants"`
}

VariantsResource represents the result from the products/X/variants.json endpoint

type Webhook

type Webhook struct {
	ID                  int        `json:"id"`
	Address             string     `json:"address"`
	Topic               string     `json:"topic"`
	Format              string     `json:"format"`
	CreatedAt           *time.Time `json:"created_at,omitempty"`
	UpdatedAt           *time.Time `json:"updated_at,omitempty"`
	Fields              []string   `json:"fields"`
	MetafieldNamespaces []string   `json:"metafield_namespaces"`
}

Webhook represents a Shopify webhook

type WebhookOptions

type WebhookOptions struct {
	Address string `url:"address,omitempty"`
	Topic   string `url:"topic,omitempty"`
}

WebhookOptions can be used for filtering webhooks on a List request.

type WebhookResource

type WebhookResource struct {
	Webhook *Webhook `json:"webhook"`
}

WebhookResource represents the result from the admin/webhooks.json endpoint

type WebhookService

type WebhookService interface {
	List(interface{}) ([]Webhook, error)
	Count(interface{}) (int, error)
	Get(int, interface{}) (*Webhook, error)
	Create(Webhook) (*Webhook, error)
	Update(Webhook) (*Webhook, error)
	Delete(int) error
}

WebhookService is an interface for interfacing with the webhook endpoints of the Shopify API. See: https://help.shopify.com/api/reference/webhook

type WebhookServiceOp

type WebhookServiceOp struct {
	// contains filtered or unexported fields
}

WebhookServiceOp handles communication with the webhook-related methods of the Shopify API.

func (*WebhookServiceOp) Count

func (s *WebhookServiceOp) Count(options interface{}) (int, error)

Count webhooks

func (*WebhookServiceOp) Create

func (s *WebhookServiceOp) Create(webhook Webhook) (*Webhook, error)

Create a new webhook

func (*WebhookServiceOp) Delete

func (s *WebhookServiceOp) Delete(ID int) error

Delete an existing webhooks

func (*WebhookServiceOp) Get

func (s *WebhookServiceOp) Get(webhookdID int, options interface{}) (*Webhook, error)

Get individual webhook

func (*WebhookServiceOp) List

func (s *WebhookServiceOp) List(options interface{}) ([]Webhook, error)

List webhooks

func (*WebhookServiceOp) Update

func (s *WebhookServiceOp) Update(webhook Webhook) (*Webhook, error)

Update an existing webhook.

type WebhooksResource

type WebhooksResource struct {
	Webhooks []Webhook `json:"webhooks"`
}

WebhooksResource is the root object for a webhook get request.

Jump to

Keyboard shortcuts

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