{"id":13546398,"url":"https://github.com/orbit-apps/elixir-shopifyapi","last_synced_at":"2025-10-12T14:09:53.520Z","repository":{"id":38844420,"uuid":"129816247","full_name":"orbit-apps/elixir-shopifyapi","owner":"orbit-apps","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-20T22:02:34.000Z","size":1314,"stargazers_count":29,"open_issues_count":8,"forks_count":5,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-08-22T10:51:19.079Z","etag":null,"topics":["library"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orbit-apps.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-04-16T23:03:03.000Z","updated_at":"2025-08-20T22:02:14.000Z","dependencies_parsed_at":"2024-06-23T03:56:00.491Z","dependency_job_id":"14d77309-ab7d-449d-ac94-a0876f2b9602","html_url":"https://github.com/orbit-apps/elixir-shopifyapi","commit_stats":null,"previous_names":["pixelunion/elixir-shopifyapi"],"tags_count":85,"template":false,"template_full_name":null,"purl":"pkg:github/orbit-apps/elixir-shopifyapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbit-apps%2Felixir-shopifyapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbit-apps%2Felixir-shopifyapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbit-apps%2Felixir-shopifyapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbit-apps%2Felixir-shopifyapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orbit-apps","download_url":"https://codeload.github.com/orbit-apps/elixir-shopifyapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbit-apps%2Felixir-shopifyapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011544,"owners_count":26084963,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["library"],"created_at":"2024-08-01T12:00:36.545Z","updated_at":"2025-10-12T14:09:53.513Z","avatar_url":"https://github.com/orbit-apps.png","language":"Elixir","funding_links":[],"categories":["Libraries","库"],"sub_categories":["Elixir"],"readme":"# ShopifyAPI and Plug.ShopifyAPI\n\n- [ShopifyAPI and Plug.ShopifyAPI](#ShopifyAPI-and-PlugShopifyAPI)\n  - [Installation](#Installation)\n  - [Installing this app in a Shop](#Installing-this-app-in-a-Shop)\n  - [Configuration](#Configuration)\n    - [API Version](#API-Version)\n    - [Supervisor](#supervisor)\n    - [Background Runner](#Background-Runner)\n    - [Shops](#Shops)\n    - [Apps](#Apps)\n    - [AuthTokens](#AuthTokens)\n  - [Webhooks](#Webhooks)\n  - [GraphQL](#GraphQL)\n  - [Telemetry](#Telemetry)\n\n## Installation\n\nThe package can be installed by adding `shopify_api` to your list of dependencies in `mix.exs`.\n\n```elixir\ndef deps do\n  [\n    {:shopify_api, github: \"pixelunion/elixir-shopifyapi\", tag: \"v0.16.3\"}\n  ]\nend\n```\n\nAdd it to your phoenix routes.\n\n```elixir\nscope \"/shop\" do\n  forward(\"/\", ShopifyAPI.Router)\nend\n```\n\nTo handle incoming webhooks from Shopify, add the `ShopifyAPI.Plugs.Webhook` to your `Endpoint` module (before the JSON parser configuration):\n\n```elixir\nplug ShopifyAPI.Plugs.Webhook,\n  app_name: \"my-app-name\",\n  prefix: \"/shopify/webhook\",\n  callback: {WebhookHandler, :handle_webhook, []}\n```\n\nIf you want persisted Apps, Shops, and Tokens add configuration to your functions.\n```elixir\nconfig :shopify_api, ShopifyAPI.AuthTokenServer,\n  initializer: {MyApp.AuthToken, :init, []},\n  persistence: {MyApp.AuthToken, :save, []}\nconfig :shopify_api, ShopifyAPI.AppServer,\n  initializer: {MyApp.ShopifyApp, :init, []},\n  persistence: {MyApp.ShopifyApp, :save, []}\nconfig :shopify_api, ShopifyAPI.ShopServer,\n  initializer: {MyApp.Shop, :init, []},\n  persistence: {MyApp.Shop, :save, []}\n```\n\n## Installing this app in a Shop\n\nThere is a boilerplate repo for quickly getting up and running at [ShopifyApp](https://github.com/pixelunion/elixir-shopify-app)\n\n1. Start something like ngrok\n2. Configure your app to allow your ngrok url as one of the redirect_urls\n3. Point your browser to `http://localhost:4000/shop/install?shop=your-shop.myshopify.com\u0026app=yourapp` and it should prompt you to login and authorize it.\n\n\n## Configuration\n\n### API Version\n\nShopify introduced API versioning here: https://help.shopify.com/en/api/versioning\n\nConfigure the version to use in your config.exs, it will default to a stable version as ref'd in the [request module](lib/shopify_api/rest/request.ex).\n\n```elixir\nconfig :shopify_api, ShopifyAPI.REST, api_version: \"2019-04\"\n```\n\n### Supervisor\n\nThe ShopifyAPI has three servers for caching commonly-used structs - `AppServer`, `ShopServer`, and `AuthTokenServer`.\nThese act as a write-through caching layer for their corresponding data structure.\n\nA supervisor `ShopifyAPI.Supervisor` is provided to start up and supervise all three servers.\nAdd it to your application's supervision tree, and define [hooks for preloading data](#Installation).\n\nNOTE: Make sure you place the supervisor after any dependencies used in preloading the data. (ie Ecto)\n\nAdd the following to your application:\n\n```elixir\ndef start(_type, _args) do\n  children = [\n    MyApp.Repo,\n    ShopifyAPI.Supervisor\n  ]\n\n  Supervisor.start_link(children, strategy: :one_for_one)\nend\n```\n\n## Webhooks\n\nTo set up your app to receive webhooks, first you'll need to add `ShopifyAPI.Plugs.Webhook` to your `Endpoint` module:\n\n```elixir\nplug ShopifyAPI.Plugs.Webhook,\n  app_name: \"my-app-name\",\n  prefix: \"/shopify/webhook\",\n  callback: {WebhookHandler, :handle_webhook, []}\n```\n\nYou'll also need to define a corresponding `WebhookHandler` module in your app:\n\n```elixir\ndefmodule WebhookHandler do\n  def handle_webhook(app, shop, domain, payload) do\n    # TODO implement me!\n  end\nend\n```\n\nAnd there you go!\n\nNow webhooks sent to `YOUR_URL/shopify/webhook` will be interpreted as webhooks for the `my-app-name` app.\nIf you append an app name to the URL in the Shopify configuration, that app will be used instead (e.g. `/shopify/webhook/private-app-name`).\n\nIf you'd like to install webhooks using ShopifyAPI, we need to do a small bit more work:\n\n```elixir\n# Add this to your configuration so that ShopifyAPI knows the webhook prefix.\nconfig :shopify_api, ShopifyAPI.Webhook, uri: \"https://your-app-url/shop/webhook\"\n```\n\nNow once a shop is installed, you can create webhook subscriptions.\nThis will automatically append your app's name to the generated webhook URL:\n\n```elixir\ntoken = ShopifyAPI.AuthTokenServer.get(\"shop domain\", \"app name\")\n\ntopic = \"orders/create\"\nserver_address = ShopifyAPI.REST.Webhook.webhook_uri(token)\nwebhook = %{topic: topic, address: server_address}\n\nShopifyAPI.REST.Webhook.create(token, %{webhook: webhook})\n```\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nand published on [HexDocs](https://hexdocs.pm). Once published, the docs can\nbe found at [https://hexdocs.pm/shopify_api](https://hexdocs.pm/shopify_api).\n\n## GraphQL\n\n`GraphQL` implementation handles GraphQL Queries against Shopify API using HTTPoison library as client, this initial implementation consists of hitting Shopify GraphQL and returning the response in a tuple `{:ok, %Response{}} | {:error, %Response{}}` containing the response and metadata(actualQueryCost, throttleStatus).\n\nConfigure the version to use in your config.exs, it will default to a stable version as ref'd in the [graphql module](lib/shopify_api/graphql.ex).\n\n\n```elixir\nconfig :shopify_api, ShopifyAPI.GraphQL, graphql_version: \"2019-07\"\n```\n\n### GraphQL Response\n\nBecause `GraphQL responses` can be a little complex we are parsing/wraping responses `%HTTPoison.response` to `%GraphQL.Response`.\n\nSuccessful response:\n\n```elixir\n{:ok, %ShopifyAPI.GraphQL.Response{response: %{}, metadata: %{}, status_code: code}}\n```\n\nFailed response:\n\n```elixir\n{:error, %HTTPoison.Response{}}\n```\n\n## Telemetry\n\nThe `shopify_api` library will emit events using the [`:telemetry`](https://github.com/beam-telemetry/telemetry) library. Consumers of `shopify_api` can then use these events for customized metrics aggregation and more.\nThe following telemetry events are generated:\n- `[:shopify_api, :rest_request, :success]`\n- `[:shopify_api, :rest_request, :failure]`\n- `[:shopify_api, :throttling, :over_limit]`\n- `[:shopify_api, :throttling, :within_limit]`\n- `[:shopify_api, :graphql_request, :success]`\n- `[:shopify_api, :graphql_request, :failure]`\n- `[:shopify_api, :bulk_operation, :success]`\n- `[:shopify_api, :bulk_operation, :failure]`\n\nAs an example, you could use an external module to instrument API requests made by `shopify_api`:\n\n```elixir\ndefmodule Instrumenter do\n  def setup do\n    events = [\n      [:shopify_api, :rest_request, :success],\n      [:shopify_api, :rest_request, :failure]\n    ]\n\n    :telemetry.attach_many(\"my-instrumenter\", events, \u0026handle_event/4, nil)\n  end\n\n  def handle_event([:shopify_api, :rest_request, :success], measurements, metadata, _config) do\n    # Ship success events\n  end\nend```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forbit-apps%2Felixir-shopifyapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forbit-apps%2Felixir-shopifyapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forbit-apps%2Felixir-shopifyapi/lists"}