{"id":13748860,"url":"https://github.com/ericcj/amz_sp_api","last_synced_at":"2025-05-09T11:31:38.047Z","repository":{"id":38351814,"uuid":"338422660","full_name":"ericcj/amz_sp_api","owner":"ericcj","description":"AmzSpApi - Unofficial Ruby gem for the Selling Partner APIs (SP-API)","archived":false,"fork":false,"pushed_at":"2024-04-23T00:21:51.000Z","size":1799,"stargazers_count":49,"open_issues_count":23,"forks_count":60,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-25T01:44:02.613Z","etag":null,"topics":["amazon","amazon-marketplace","amazon-mws","amazon-selling-partner","mws","mws-api","mws-sdk","selling-partner-api","selling-partner-api-sdk","sp-api"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/ericcj.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-02-12T20:12:16.000Z","updated_at":"2025-04-18T13:41:43.000Z","dependencies_parsed_at":"2024-04-10T21:33:27.476Z","dependency_job_id":null,"html_url":"https://github.com/ericcj/amz_sp_api","commit_stats":{"total_commits":37,"total_committers":4,"mean_commits":9.25,"dds":0.1351351351351351,"last_synced_commit":"84cd2dfc1398eee632da9b6f3ebfba25f591877a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericcj%2Famz_sp_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericcj%2Famz_sp_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericcj%2Famz_sp_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericcj%2Famz_sp_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericcj","download_url":"https://codeload.github.com/ericcj/amz_sp_api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253240350,"owners_count":21876593,"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":["amazon","amazon-marketplace","amazon-mws","amazon-selling-partner","mws","mws-api","mws-sdk","selling-partner-api","selling-partner-api-sdk","sp-api"],"created_at":"2024-08-03T07:00:51.030Z","updated_at":"2025-05-09T11:31:33.019Z","avatar_url":"https://github.com/ericcj.png","language":"Ruby","readme":"# amz_sp_api\n\nAmzSpApi - Unofficial Ruby gem for the Amazon Selling Partner API (SP-API)\n\nThis SDK is automatically generated by running [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) on each model from https://github.com/amzn/selling-partner-api-models using the [codegen.sh](codegen.sh) script.  \n\nAuto-generated documentation is nested here:  This is a handy way to see all the API model class names and corresponding files you need to require for them, e.g. require 'finances-api-model' to use https://www.rubydoc.info/gems/amz_sp_api/AmzSpApi/FinancesApiModel/DefaultApi\n\nbut https://developer-docs.amazon.com/sp-api is more comprehensive. \n\n## Installation\n\nAdd the gem to your Gemfile as per https://rubygems.org/gems/amz_sp_api\n\n## Getting Started\n\nPlease follow the [installation](#installation) procedure and then run the following code, see [sp_configuration.rb](lib/sp_configuration.rb) for all options:\n```ruby\n# Load the gem and specific api model you'd like to use\n\nrequire 'amz_sp_api'\nrequire 'fulfillment-outbound-api-model'\n\n  AmzSpApi.configure do |config|\n    config.refresh_token = \n    config.client_id = \n    config.client_secret = \n\n    # either use these:\n    config.aws_access_key_id = \n    config.aws_secret_access_key = \n\n    # OR config.credentials_provider which is passed along to https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Sigv4/Signer.html, e.g.\n    # require 'aws-sdk-core'\n    # config.credentials_provider = Aws::STS::Client.new(\n    #     region: AmzSpApi::SpConfiguration::AWS_REGION_MAP['eu'],\n    #     access_key_id: ,\n    #     secret_access_key: \n    #   ).assume_role(role_arn: , role_session_name: SecureRandom.uuid)\n\n    config.region = 'eu'\n    config.timeout = 20 # seconds\n    # config.debugging = true\n\n    # optional lambdas for caching LWA access token instead of requesting it each time, e.g.:\n    config.save_access_token = -\u003e (access_token_key, token) do\n      Rails.cache.write(\"SPAPI-TOKEN-#{access_token_key}\", token[:access_token], expires_in: token[:expires_in] - 60)\n    end\n    config.get_access_token = -\u003e (access_token_key) { Rails.cache.read(\"SPAPI-TOKEN-#{access_token_key}\") }\n  end\n\n  begin\n    api = AmzSpApi::FulfillmentOutboundApiModel::FbaOutboundApi.new(AmzSpApi::SpApiClient.new)\n    p api.list_all_fulfillment_orders.payload\n  rescue AmzSpApi::ApiError =\u003e e\n    puts \"Exception when calling SP-API: #{e}\"\n  end\n```\n\n## Restricted operations\n\nConfigure as per above but also create a new client for each restrictedResources you need, e.g.:\n\n```\nrequire 'orders-api-model'\n\nclient = AmzSpApi::RestrictedSpApiClient.new({\n  'restrictedResources' =\u003e [\n    {\n      'method' =\u003e 'GET',\n      'path' =\u003e \"/orders/v0/orders\",\n      'dataElements' =\u003e ['buyerInfo', 'shippingAddress']\n    }\n  ]\n})\napi_orders = AmzSpApi::OrdersApiModel::OrdersV0Api.new(client)\napi_orders.get_orders(marketplace_ids, created_after: 1.day.ago.iso8601)\n\nclient = AmzSpApi::RestrictedSpApiClient.new({\n  'restrictedResources' =\u003e [\n    {\n      'method' =\u003e 'GET',\n      'path' =\u003e \"/orders/v0/orders/#{my_order_id}\",\n      'dataElements' =\u003e ['buyerInfo', 'shippingAddress']\n    }\n  ]\n})\napi_orders = AmzSpApi::OrdersApiModel::OrdersV0Api.new(client)\napi_orders.get_order(my_order_id)\n\n# or you can use models AmzSpApi::RestrictedSpApiClient.new(AmzSpApi::TokensApiModel::CreateRestrictedDataTokenRequest.new(restricted_resources: [\n        AmzSpApi::TokensApiModel::RestrictedResource.new(...\n```\n\n## Feeds and reports\n\nThis gem also offers encrypt/decrypt helper methods for feeds and reports, but actually using that API as per https://developer-docs.amazon.com/sp-api/docs/ requires the following calls, e.g. for feeds but reports is the same pattern:\n\n```ruby\nfeeds = AmzSpApi::FeedsApiModel::FeedsApi.new(AmzSpApi::SpApiClient.new)\nresponse = feeds.create_feed_document({\"contentType\" =\u003e content_type})\n# PUT to response.url with lowercase \"content-type\" header, it's already pre-signed\nresponse = feeds.create_feed({\"feedType\" =\u003e feed_type, \"marketplaceIds\" =\u003e marketplace_ids, \"inputFeedDocumentId\" =\u003e response.feed_document_id})\nresponse = feeds.get_feed(response.feed_id)\nresult_feed_document_id = response.result_feed_document_id # present once it is successful\nresponse = feeds.get_feed_document(result_feed_document_id)\n# GET response.url into compressed, again it's pre-signed so no authorization needed\nreport = AmzSpApi.inflate_document(compressed, response)\n# you should capture the HTTP headers from downloading url as well since it's often Cp1252\nreport.force_encoding($1) if headers['Content-Type'] =~ /charset *= *([^;]+)/\nCSV.parse(report, headers: true, col_sep: \"\\t\", liberal_parsing: true) # if it's a CSV report type\n```\n\n## Thanks\n\nto https://github.com/patterninc/muffin_man as the basis for [sp_api_client.rb](lib/sp_api_client.rb)\n","funding_links":[],"categories":["Docs"],"sub_categories":["Library"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericcj%2Famz_sp_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericcj%2Famz_sp_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericcj%2Famz_sp_api/lists"}