{"id":13546408,"url":"https://github.com/bold-commerce/go-shopify","last_synced_at":"2025-04-02T18:30:41.549Z","repository":{"id":38617448,"uuid":"143448238","full_name":"bold-commerce/go-shopify","owner":"bold-commerce","description":"Go client for the Shopify API","archived":false,"fork":true,"pushed_at":"2025-02-09T20:11:55.000Z","size":670,"stargazers_count":345,"open_issues_count":13,"forks_count":266,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-29T12:12:21.838Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"getconversio/go-shopify","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bold-commerce.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-03T16:09:29.000Z","updated_at":"2025-03-20T20:34:58.000Z","dependencies_parsed_at":"2023-02-01T01:01:20.343Z","dependency_job_id":null,"html_url":"https://github.com/bold-commerce/go-shopify","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bold-commerce%2Fgo-shopify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bold-commerce%2Fgo-shopify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bold-commerce%2Fgo-shopify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bold-commerce%2Fgo-shopify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bold-commerce","download_url":"https://codeload.github.com/bold-commerce/go-shopify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246869634,"owners_count":20847166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:00:36.689Z","updated_at":"2025-04-02T18:30:40.527Z","avatar_url":"https://github.com/bold-commerce.png","language":"Go","funding_links":[],"categories":["Libraries","Go","库"],"sub_categories":["Golang"],"readme":"# go-shopify\n\nThe new home of Conversio's Shopify Go library.\n\n**Note**: The library does not have implementations of all Shopify resources, but it is being used in production 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.\n\n[![Build Status](https://travis-ci.org/bold-commerce/go-shopify.svg?branch=master)](https://travis-ci.org/bold-commerce/go-shopify)\n[![codecov](https://codecov.io/gh/bold-commerce/go-shopify/branch/master/graph/badge.svg)](https://codecov.io/gh/bold-commerce/go-shopify) [![Join the chat at https://gitter.im/bold-commerce/go-shopify](https://badges.gitter.im/bold-commerce/go-shopify.svg)](https://gitter.im/bold-commerce/go-shopify?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n## Supported Go Versions\n\nThis library is tested automatically against the latest version of Go (currently 1.22) and the two previous versions (1.21, 1.20) but should also work with older versions.\n\n## Install v4\n\n```console\n$ go get github.com/bold-commerce/go-shopify/v4\n```\n\n## Use v4\n\n```go\nimport \"github.com/bold-commerce/go-shopify/v4\"\n```\n\nThis gives you access to the `goshopify` package.\n\n## Install v3\n\n```console\n$ go get github.com/bold-commerce/go-shopify/v3\n```\n\n## Use v3\n\n```go\nimport \"github.com/bold-commerce/go-shopify/v3\"\n```\n\nThis gives you access to the `goshopify` package.\n\n## Install v2\n\n```console\n$ go get github.com/bold-commerce/go-shopify\n```\n\n## Use v2\n\n```go\nimport \"github.com/bold-commerce/go-shopify\"\n```\n\nThis gives you access to the `goshopify` package.\n\n#### Oauth\n\nIf you don't have an access token yet, you can obtain one with the oauth flow.\nSomething like this will work:\n\n```go\n// Create an app somewhere.\napp := goshopify.App{\n    ApiKey: \"abcd\",\n    ApiSecret: \"efgh\",\n    RedirectUrl: \"https://example.com/shopify/callback\",\n    Scope: \"read_products,read_orders\",\n}\n\n// Create an oauth-authorize url for the app and redirect to it.\n// In some request handler, you probably want something like this:\nfunc MyHandler(w http.ResponseWriter, r *http.Request) {\n    shopName := r.URL.Query().Get(\"shop\")\n    state := \"nonce\"\n    authUrl := app.AuthorizeUrl(shopName, state)\n    http.Redirect(w, r, authUrl, http.StatusFound)\n}\n\n// Fetch a permanent access token in the callback\nfunc MyCallbackHandler(w http.ResponseWriter, r *http.Request) {\n    // Check that the callback signature is valid\n    if ok, _ := app.VerifyAuthorizationURL(r.URL); !ok {\n        http.Error(w, \"Invalid Signature\", http.StatusUnauthorized)\n        return\n    }\n\n    query := r.URL.Query()\n    shopName := query.Get(\"shop\")\n    code := query.Get(\"code\")\n    ctx := context.TODO() // adds context which will be used in GetAccessToken below\n    token, err := app.GetAccessToken(ctx, shopName, code)\n\n    // Do something with the token, like store it in a DB.\n}\n```\n\n#### Api calls with a token\n\nWith a permanent access token, you can make API calls like this:\n\n```go\n// Create an app somewhere.\napp := goshopify.App{\n    ApiKey: \"abcd\",\n    ApiSecret: \"efgh\",\n    RedirectUrl: \"https://example.com/shopify/callback\",\n    Scope: \"read_products\",\n}\n\n// Create a new API client\nclient, err := goshopify.NewClient(app, \"shopname\", \"token\")\n\n// Fetch the number of products.\nnumProducts, err := client.Product.Count(nil)\n```\n\n#### Private App Auth\n\nPrivate Shopify apps use basic authentication and do not require going through the OAuth flow. Here is an example:\n\n```go\n// Create an app somewhere.\napp := goshopify.App{\n\tApiKey: \"apikey\",\n\tPassword: \"apipassword\",\n}\n\n// Create a new API client (notice the token parameter is the empty string)\nclient, err := goshopify.NewClient(app, \"shopname\", \"\")\n\n// Fetch the number of products.\nnumProducts, err := client.Product.Count(nil)\n```\n\n### Client Options\n\nWhen creating a client there are configuration options you can pass to NewClient. Simply use the last variadic param and\npass in the built in options or create your own and manipulate the client. See [options.go](https://github.com/bold-commerce/go-shopify/blob/master/options.go)\nfor more details.\n\n#### WithVersion\n\nRead more details on the [Shopify API Versioning](https://shopify.dev/concepts/about-apis/versioning)\nto understand the format and release schedules. You can use `WithVersion` to specify a specific version\nof the API. If you do not use this option you will be defaulted to the oldest stable API.\n\n```go\nclient, err := goshopify.NewClient(app, \"shopname\", \"\", goshopify.WithVersion(\"2019-04\"))\n```\n\n#### WithRetry\n\nShopify [Rate Limits](https://shopify.dev/concepts/about-apis/rate-limits) their API and if this happens to you they\nwill send a back off (usually 2s) to tell you to retry your request. To support this functionality seamlessly within\nthe client a `WithRetry` option exists where you can pass an `int` of how many times you wish to retry per-request\nbefore returning an error. `WithRetry` additionally supports retrying HTTP503 errors.\n\n```go\nclient, err := goshopify.NewClient(app, \"shopname\", \"\", goshopify.WithRetry(3))\n```\n\n#### Query options\n\nMost API functions take an options `interface{}` as parameter. You can use one\nfrom the library or create your own. For example, to fetch the number of\nproducts created after January 1, 2016, you can do:\n\n```go\n// Create standard CountOptions\ndate := time.Date(2016, time.January, 1, 0, 0, 0, 0, time.UTC)\noptions := goshopify.CountOptions{createdAtMin: date}\n\n// Use the options when calling the API.\nnumProducts, err := client.Product.Count(options)\n```\n\nThe options are parsed with Google's\n[go-querystring](https://github.com/google/go-querystring) library so you can\nuse custom options like this:\n\n```go\n// Create custom options for the orders.\n// Notice the `url:\"status\"` tag\noptions := struct {\n    Status string `url:\"status\"`\n}{\"any\"}\n\n// Fetch the order count for orders with status=\"any\"\norderCount, err := client.Order.Count(options)\n```\n\n#### Using your own models\n\nNot all endpoints are implemented right now. In those case, feel free to\nimplement them and make a PR, or you can create your own struct for the data\nand use `NewRequest` with the API client. This is how the existing endpoints\nare implemented.\n\nFor example, let's say you want to fetch webhooks. There's a helper function\n`Get` specifically for fetching stuff so this will work:\n\n```go\n// Declare a model for the webhook\ntype Webhook struct {\n    Id int         `json:\"id\"`\n    Address string `json:\"address\"`\n}\n\n// Declare a model for the resource root.\ntype WebhooksResource struct {\n    Webhooks []Webhook `json:\"webhooks\"`\n}\n\nfunc FetchWebhooks() ([]Webhook, error) {\n    path := \"admin/webhooks.json\"\n    resource := new(WebhooksResource)\n    client, _ := goshopify.NewClient(app, \"shopname\", \"token\")\n\n    // resource gets modified when calling Get\n    err := client.Get(path, resource, nil)\n\n    return resource.Webhooks, err\n}\n```\n\n#### Webhooks verification\n\nIn order to be sure that a webhook is sent from ShopifyApi you could easily verify\nit with the `VerifyWebhookRequest` method.\n\nFor example:\n\n```go\nfunc ValidateWebhook(httpRequest *http.Request) (bool) {\n    shopifyApp := goshopify.App{ApiSecret: \"ratz\"}\n    return shopifyApp.VerifyWebhookRequest(httpRequest)\n}\n```\n\n## Develop and test\n\n`docker` and `docker-compose` must be installed\n\n### Mac/Linux/Windows with make\n\nUsing the make file is the easiest way to get started with the tests and wraps the manual steps below with easy to use\nmake commands.\n\n```shell\nmake \u0026\u0026 make test\n```\n\n#### Makefile goals\n\n- `make` or `make container`: default goal is to make the `go-shopify:latest` build container\n- `make test`: run go test in the container\n- `make clean`: deletes the `go-shopify:latest` image and coverage output\n- `make coverage`: generates the coverage.html and opens it\n\n### Manually\n\nTo run the tests you will need the `go-shopify:latest` image built to run your tests, to do this run\n\n```\ndocker-compose build test\n```\n\nTo run tests you can use run\n\n```shell\ndocker-compose run --rm tests\n```\n\nTo create a coverage profile run the following to generate a coverage.html\n\n```\ndocker-compose run --rm dev sh -c 'go test -coverprofile=coverage.out ./... \u0026\u0026 go tool cover -html coverage.out -o coverage.html'\n```\n\nWhen done testing and you want to cleanup simply run\n\n```\ndocker image rm go-shopify:latest\n```\n\nRead the docker-compose.yml and Dockerfile for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbold-commerce%2Fgo-shopify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbold-commerce%2Fgo-shopify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbold-commerce%2Fgo-shopify/lists"}