Documentation
¶
Index ¶
- Constants
- Variables
- func WithAccessToken(ctx context.Context, token AccessToken) context.Context
- func WithOAuthToken(ctx context.Context, token *OAuthToken) context.Context
- func WithShop(ctx context.Context, shop Shop) context.Context
- type APIKey
- type APISecret
- type AccessToken
- type AdminClient
- func (c *AdminClient) CreateOrUpdateScriptTag(ctx context.Context, scriptTag ScriptTag) (*ScriptTag, error)
- func (c *AdminClient) DeleteScriptTag(ctx context.Context, id ScriptTagID) error
- func (c *AdminClient) EnsureScriptTag(ctx context.Context, scriptTag ScriptTag) (*ScriptTag, error)
- func (c *AdminClient) GetAllScriptTags(ctx context.Context, fields SelectedFields) ([]ScriptTag, error)
- func (c *AdminClient) GetOAuthToken(ctx context.Context, apiKey APIKey, apiSecret APISecret, code string) (*OAuthToken, error)
- func (c *AdminClient) GetScriptTag(ctx context.Context, id ScriptTagID, fields SelectedFields) (*ScriptTag, error)
- func (c *AdminClient) GetScriptTags(ctx context.Context, pagination *Pagination, fields SelectedFields) ([]ScriptTag, error)
- func (c *AdminClient) GetScriptTagsCount(ctx context.Context) (int, error)
- type OAuthToken
- type Pagination
- type Permission
- type ProductTag
- type ProductTags
- type Scope
- type ScriptTag
- type ScriptTagDisplayScope
- type ScriptTagEvent
- type ScriptTagID
- type SelectedFields
- type Shop
Constants ¶
const ( // DefaultLimit is the default limit, as specified by Shopify. DefaultLimit = 50 // MaxLimit is the maximum allowed limit, as specified by Shopify. MaxLimit = 250 )
const ( // PermissionReadContent represents read access to Article, Blog, Comment, Page, and Redirect. PermissionReadContent = Permission("read_content") // PermissionWriteContent represents write access to Article, Blog, Comment, Page, and Redirect. PermissionWriteContent = Permission("write_content") // PermissionReadThemes represents read access to Asset and Theme. PermissionReadThemes = Permission("read_themes") // PermissionWriteThemes represents write access to Asset and Theme. PermissionWriteThemes = Permission("write_themes") // PermissionReadProducts represents read access to Product, Product Variant, Product Image, Collect, Custom Collection, and Smart Collection. PermissionReadProducts = Permission("read_products") // PermissionWriteProducts represents write access to Product, Product Variant, Product Image, Collect, Custom Collection, and Smart Collection. PermissionWriteProducts = Permission("write_products") // PermissionReadProductListings represents read access to Product Listing, and Collection Listing. PermissionReadProductListings = Permission("read_product_listings") // PermissionReadCustomers represents read access to Customer and Saved Search. PermissionReadCustomers = Permission("read_customers") // PermissionWriteCustomers represents write access to Customer and Saved Search. PermissionWriteCustomers = Permission("write_customers") // PermissionReadOrders represents read access to Order, Transaction and Fulfillment. PermissionReadOrders = Permission("read_orders") // PermissionWriteOrders represents write access to Order, Transaction and Fulfillment. PermissionWriteOrders = Permission("write_orders") // PermissionReadAllOrders represents read grants access to all orders rather than the default window of 60 days worth of orders. This OAuth scope is used in conjunction with read_orders, or write_orders. You need to request this scope from your Partner Dashboard before adding it to your app. PermissionReadAllOrders = Permission("read_all_orders") // PermissionReadDraftOrders represents read access to Draft Order. PermissionReadDraftOrders = Permission("read_draft_orders") // PermissionWriteDraftOrders represents write access to Draft Order. PermissionWriteDraftOrders = Permission("write_draft_orders") // PermissionReadInventory represents read access to Inventory Level and Inventory Item. PermissionReadInventory = Permission("read_inventory") // PermissionWriteInventory represents write access to Inventory Level and Inventory Item. PermissionWriteInventory = Permission("write_inventory") // PermissionReadLocations represents read access to Location. PermissionReadLocations = Permission("read_locations") // PermissionReadScriptTags represents read access to Script Tag. PermissionReadScriptTags = Permission("read_script_tags") // PermissionWriteScriptTags represents write access to Script Tag. PermissionWriteScriptTags = Permission("write_script_tags") // PermissionReadFulfillments represents read access to Fulfillment Service. PermissionReadFulfillments = Permission("read_fulfillments") // PermissionWriteFulfillments represents write access to Fulfillment Service. PermissionWriteFulfillments = Permission("write_fulfillments") // PermissionReadShipping represents read access to Carrier Service, Country and Province. PermissionReadShipping = Permission("read_shipping") // PermissionWriteShipping represents write access to Carrier Service, Country and Province. PermissionWriteShipping = Permission("write_shipping") // PermissionReadAnalytics represents read access to Analytics API. PermissionReadAnalytics = Permission("read_analytics") // PermissionReadUsers represents read access to User (SHOPIFY PLUS). PermissionReadUsers = Permission("read_users") // PermissionWriteUsers represents write access to User (SHOPIFY PLUS). PermissionWriteUsers = Permission("write_users") // PermissionReadCheckouts represents read access to Checkouts. PermissionReadCheckouts = Permission("read_checkouts") // PermissionWriteCheckouts represents write access to Checkouts. PermissionWriteCheckouts = Permission("write_checkouts") // PermissionReadReports represents read access to Reports. PermissionReadReports = Permission("read_reports") // PermissionWriteReports represents write access to Reports. PermissionWriteReports = Permission("write_reports") // PermissionReadPriceRules represents read access to Price Rules. PermissionReadPriceRules = Permission("read_price_rules") // PermissionWritePriceRules represents write access to Price Rules. PermissionWritePriceRules = Permission("write_price_rules") // PermissionReadMarketingEvents represents read access to Marketing Event. PermissionReadMarketingEvents = Permission("read_marketing_events") // PermissionWriteMarketingEvents represents write access to Marketing Event. PermissionWriteMarketingEvents = Permission("write_marketing_events") // PermissionReadResourceFeedbacks represents read access to ResourceFeedback. PermissionReadResourceFeedbacks = Permission("read_resource_feedbacks") // PermissionWriteResourceFeedbacks represents write access to ResourceFeedback. PermissionWriteResourceFeedbacks = Permission("write_resource_feedbacks") // PermissionReadShopifyPaymentsPayouts represents read access to Shopify Payments Payouts, and Transactions. PermissionReadShopifyPaymentsPayouts = Permission("read_shopify_payments_payouts") // PermissionUnauthenticatedReadProductListings represents read unauthenticated access to read the Product and Collection objects. PermissionUnauthenticatedReadProductListings = Permission("unauthenticated_read_product_listings") // PermissionUnauthenticatedWriteCheckouts represents write unauthenticated access to the Checkout object. PermissionUnauthenticatedWriteCheckouts = Permission("unauthenticated_write_checkouts") // PermissionUnauthenticatedWriteCustomers represents write unauthenticated access to the Customer object. PermissionUnauthenticatedWriteCustomers = Permission("unauthenticated_write_customers") // PermissionUnauthenticatedReadCustomerTags represents read unauthenticated access to read the tags field on the Customer object. PermissionUnauthenticatedReadCustomerTags = Permission("unauthenticated_read_customer_tags") // PermissionUnauthenticatedReadContent represents read unauthenticated access to read storefront content, such as Article, Blog, and Comment objects. PermissionUnauthenticatedReadContent = Permission("unauthenticated_read_content") )
Variables ¶
var Debug = getDebug()
Debug is a boolean variable that, if set to true, will cause HTTP requests and responses to be printed.
var DefaultAdminClient = &AdminClient{}
DefaultAdminClient is the default admin client.
var DefaultHTTPClient = newHTTPClient()
DefaultHTTPClient is the default HTTP client used by AdminClient instances.
Functions ¶
func WithAccessToken ¶
func WithAccessToken(ctx context.Context, token AccessToken) context.Context
WithAccessToken returns a context that references an access token.
This will override any previously set OAuth token with WithOAuthToken.
func WithOAuthToken ¶
func WithOAuthToken(ctx context.Context, token *OAuthToken) context.Context
WithOAuthToken returns a context that references an OAuth token.
This will override any previously set access token with WithAccessToken.
Types ¶
type AccessToken ¶
type AccessToken string
AccessToken represents an access token.
func GetAccessToken ¶
func GetAccessToken(ctx context.Context) (AccessToken, bool)
GetAccessToken returns the access token associated to a context.
type AdminClient ¶
type AdminClient struct { // HTTPClient is the HTTP client to use for requests. // // If none is specified, http.DefaultClient is used. HTTPClient *http.Client }
AdminClient represents a Shopify client, that can interact with the Shopify REST Admin API.
An AdminClient takes its credentials from the specified context. See WithShop and WithAccessToken.
func (*AdminClient) CreateOrUpdateScriptTag ¶
func (c *AdminClient) CreateOrUpdateScriptTag(ctx context.Context, scriptTag ScriptTag) (*ScriptTag, error)
CreateOrUpdateScriptTag creates or updates a script tag.
If the specified script tag has an ID, an update is attempted.
Shopify requires absolute HTTPS URLs for script tags. This method however supports relative URL and assumes that a relative URL is relative to the shop URL.
func (*AdminClient) DeleteScriptTag ¶
func (c *AdminClient) DeleteScriptTag(ctx context.Context, id ScriptTagID) error
DeleteScriptTag deletes a script tag.
func (*AdminClient) EnsureScriptTag ¶
EnsureScriptTag makes sure that a specified script tag is registered in the shop.
If the scriptTag has an ID, an optimistic GET is attempted first. If the GET succeeds and the script tag is identical, the function exits immediately. No duplicates are removed in that case.
Otherwise, all script tags are fetched and compared to the specified one. The first script tag that matches exactly is kept (and returned). Any additional duplicate script tag is deleted. If no exact match is found, a new script tag is created.
func (*AdminClient) GetAllScriptTags ¶
func (c *AdminClient) GetAllScriptTags(ctx context.Context, fields SelectedFields) ([]ScriptTag, error)
GetAllScriptTags retrieves a list of all script tags.
func (*AdminClient) GetOAuthToken ¶
func (c *AdminClient) GetOAuthToken(ctx context.Context, apiKey APIKey, apiSecret APISecret, code string) (*OAuthToken, error)
GetOAuthToken recovers a permanent access token for the associated shop, using the specified code.
func (*AdminClient) GetScriptTag ¶
func (c *AdminClient) GetScriptTag(ctx context.Context, id ScriptTagID, fields SelectedFields) (*ScriptTag, error)
GetScriptTag fetches a script tag by ID.
If no such script tag exists, a nil script tag and no error is returned.
func (*AdminClient) GetScriptTags ¶
func (c *AdminClient) GetScriptTags(ctx context.Context, pagination *Pagination, fields SelectedFields) ([]ScriptTag, error)
GetScriptTags retrieves a list of script tags.
To fetch the complete list, use GetAllScriptTags.
func (*AdminClient) GetScriptTagsCount ¶
func (c *AdminClient) GetScriptTagsCount(ctx context.Context) (int, error)
GetScriptTagsCount retrieves the count of all script tags.
type OAuthToken ¶
type OAuthToken struct { AccessToken AccessToken `json:"access_token"` Scope Scope `json:"scope"` }
OAuthToken represents an OAuth token as received from a shop.
func GetOAuthToken ¶
func GetOAuthToken(ctx context.Context) (*OAuthToken, bool)
GetOAuthToken returns the OAuth token associated to a context.
func (OAuthToken) Equal ¶
func (t OAuthToken) Equal(other OAuthToken) bool
Equal compares two OAuth tokens.
type Pagination ¶
Pagination represents pagination options.
type Permission ¶
type Permission string
Permission represents an OAuth scope, as defined at https://help.shopify.com/en/api/getting-started/authentication/oauth/scopes.
type ProductTags ¶
type ProductTags []ProductTag
ProductTags represents a list of product tags.
func ParseProductTags ¶
func ParseProductTags(s string) (ProductTags, error)
ParseProductTags parses a product tags string.
Empty tags are automatically removed as they are invalid.
func (ProductTags) String ¶
func (t ProductTags) String() string
type Scope ¶
type Scope []Permission
Scope represents a list of permissions.
func ParseScope ¶
ParseScope parses a string of comma-separated permissions.
If the string has an incorrect format, an error is returned.
func (Scope) MarshalJSON ¶
MarshalJSON implements JSON marshalling.
func (*Scope) UnmarshalJSON ¶
UnmarshalJSON implements JSON unmarshalling
type ScriptTag ¶
type ScriptTag struct { CreatedAt time.Time `json:"created_at,omitempty"` Event ScriptTagEvent `json:"event"` ID ScriptTagID `json:"id"` Src string `json:"src"` DisplayScope ScriptTagDisplayScope `json:"display_scope,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` }
ScriptTag represents a script tag.
type ScriptTagDisplayScope ¶
type ScriptTagDisplayScope string
ScriptTagDisplayScope represents a script tag display scope.
const ( // ScriptTagDisplayScopeOnlineStore indicates that a script tag must be // included only on the web storefront. ScriptTagDisplayScopeOnlineStore ScriptTagDisplayScope = "online_store" // ScriptTagDisplayScopeOrderStatus indicates that a script tag must be // included only on the order status page. ScriptTagDisplayScopeOrderStatus ScriptTagDisplayScope = "order_status" // ScriptTagDisplayScopeAll indicates that a script tag must be // included on all pages. ScriptTagDisplayScopeAll ScriptTagDisplayScope = "all" )
type ScriptTagEvent ¶
type ScriptTagEvent string
ScriptTagEvent represents a script tag event.
const ( // ScriptTagEventOnLoad is the only possible value. ScriptTagEventOnLoad ScriptTagEvent = "onload" )
type SelectedFields ¶
type SelectedFields []string
SelectedFields represents a list of fields to fetch.