{"id":13546406,"url":"https://github.com/oussama4/gopify","last_synced_at":"2025-04-14T05:17:49.215Z","repository":{"id":57630744,"uuid":"408144223","full_name":"oussama4/gopify","owner":"oussama4","description":"Simple Shopify app development with Go.","archived":false,"fork":false,"pushed_at":"2022-04-10T22:26:46.000Z","size":43,"stargazers_count":29,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-14T05:17:38.739Z","etag":null,"topics":["ecommerce","go","golang","shopify"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oussama4.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":"2021-09-19T14:08:34.000Z","updated_at":"2025-01-29T04:15:19.000Z","dependencies_parsed_at":"2022-09-26T20:11:34.122Z","dependency_job_id":null,"html_url":"https://github.com/oussama4/gopify","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oussama4%2Fgopify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oussama4%2Fgopify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oussama4%2Fgopify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oussama4%2Fgopify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oussama4","download_url":"https://codeload.github.com/oussama4/gopify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248824694,"owners_count":21167345,"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":["ecommerce","go","golang","shopify"],"created_at":"2024-08-01T12:00:36.653Z","updated_at":"2025-04-14T05:17:49.178Z","avatar_url":"https://github.com/oussama4.png","language":"Go","funding_links":[],"categories":["Libraries","库"],"sub_categories":["Golang"],"readme":"# Gopify\n\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/oussama4/gopify.svg)](https://pkg.go.dev/github.com/oussama4/gopify)\n\n**Gopify** is a simple package for developing Shopify applications in Go.\n\n\n## Table of Contents\n\n - [Usage](#usage)\n   - [Oauth](#oauth)\n\t - [Start oauth process](#start-oauth-process)\n\t - [Oauth callback](#oauth-callback)\n   - [API calls](#api-calls)\n\t - [REST](#rest)\n\t - [Graphql](#graphql)\n\t - [Rate limiting](#rate-limiting)\n   - [Session tokens](#session-tokens)\n   - [Verify a Shopify request](#verify-a-shopify-request)\n   - [Verify a webhook](#verify-a-webhook)\n\n\n## Usage\n### Oauth\nWhen developing a public or custom Shopify application you need to get an access token using oauth to use Shopify APIs.\n\n#### Start oauth process\nThe first thing you need to do to use this package is to create a Gopify instance like the following:\n```go\napp := \u0026gopify.Gopify{\n\t\tApiKey:      \"key\",\n\t\tApiSecret:   \"secret\",\n\t\tRedirectUrl: \"https://example.com/auth/callback\",\n\t\tScopes:      []string{\"read_products\",\"read_orders\"},\n\t}\n```\n\nAdd a http handler to trigger the oauth process.\n\n```go\nfunc startOauth(w http.ResponseWriter, r *http.Request) {\n    shopName := r.URL.Query().Get(\"shop\")\n    authUrl := app.AuthorizationUrl(shopName, \"unique token\")\n    http.Redirect(w, r, authUrl, http.StatusFound)\n}\n```\n\n#### Oauth callback\nAfter Shopify authenticates your app, it will send a request to the redirect url that you provided to `gopify.Gopify{}` above. Now you can obtain an access token using `AccessToken` method.\n\n```go\nfunc oauthCallback(w http.ResponseWriter, r *http.Request) {\n\tshopName := r.URL.Query().Get(\"shop\")\n\tcode := r.URL.Query().Get(\"code\")\n\ttoken, err := app.AccessToken(shopName, code)\n\n\t// Do something with the token, like querying shopify API.\n\t...\n\n\t// redirect to your application home page\n\thttp.Redirect(w, r, \"app url\", http.StatusFound)\n}\n```\n\n\n### API calls\nWe can make calls to both Shopify APIs, REST and Graphql using the `Client` object provided by this package.\n\n```go\nclient := gopify.NewClient(\"example.myshopify.com\", \"access token\")\n```\n\nWe can can also pass other options to NewClient like the API version, http timeout, ...\n\n```go\n// We can use WithVersion to specify which API version\nclient := gopify.NewClient(\"example.myshopify.com\", \"access token\", gopify.WithVersion(\"2022-04\"))\n\n// Use WithTimeout to set a custom http timeout instead of 10 seconds\nclient := gopify.NewClient(\"example.myshopify.com\", \"access token\", WithTimeout(20))\n```\n\n#### REST\n```go\n// Get a list of 10 products\nproducts := []struct {\n\tTitle string\n}{}\nqueryParams := url.Values{\n\t\"limit\": {\"10\"},\n}\n_, err := client.Get(\"products.json\", queryParams, \u0026products)\n\n// Create a product\nproduct := struct {\n\tTitle string\n}{\n\tTitle: \"default\",\n}\nresponseBody := map[string]any{}\n_, err := client.Post(\"products.json\", product, \u0026responseBody)\n```\n\n#### Graphql\nTo send a Graphql query, we use the `Graphql` method defined in the api `Client` type.\n\n```go\nquery := `\n\t{\n      products (first: 10) {\n        edges {\n          node {\n            id\n            title\n          }\n        }\n      }\n    }\n`\n// the second parameter is for query variables, here we pass nil because we don't have any variables\nproducts, nil := client.Graphql(query, nil)\n```\n\n#### Rate limiting\nShopify APIs are rate limited, so if that happens you can use the `WithRetry` option to specify how many times to retry a request.\n\n```go\n// retry the request 10 times when hit the rate limit\nclient := gopify.NewClient(\"example.myshopify.com\", \"access token\", WithRetry(10))\n```\n\n### Session tokens\nIf you are building an [embedded Shopify app](https://shopify.dev/apps/getting-started/app-types#embedded-apps) then you need to authenticate your app with [session tokens](https://shopify.dev/apps/auth/session-tokens).\n\nThis package provides you with facilities for decoding a session token and extracting its payload, and also a way to verify the authenticity of the token.\n\n```go\n// decode the token \npayload, err := app.DecodeSessionToken(\"token\")\n\n// verify the signature of the token\nerr := app.VerifyTokenSignature(\"token\")\n```\n\nThere is also a higher level way to verify the authenticity of token using the [VerifyToken](https://pkg.go.dev/github.com/oussama4/gopify#Gopify.VerifyToken) http middleware.\n\n### Verify a Shopify request\nTo verify the authenticity of the request from Shopify we can verify the signature of a hmac parameter included in every request from shopify using [VerifyRequest](https://pkg.go.dev/github.com/oussama4/gopify#Gopify.VerifyRequest) http middleware.\n\n### Verify a webhook\nTo verify that a webhook request is from Shopify we can use [VerifyWebhook](https://pkg.go.dev/github.com/oussama4/gopify#Gopify.VerifyWebhook) function.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foussama4%2Fgopify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foussama4%2Fgopify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foussama4%2Fgopify/lists"}