{"id":13748857,"url":"https://github.com/amzapi/selling-partner-api-sdk","last_synced_at":"2025-05-09T11:31:30.482Z","repository":{"id":41152142,"uuid":"328588685","full_name":"amzapi/selling-partner-api-sdk","owner":"amzapi","description":"Golang toolkit for working with Amazon's Selling Partner API (SP-API)","archived":false,"fork":false,"pushed_at":"2024-10-09T18:17:56.000Z","size":196,"stargazers_count":69,"open_issues_count":17,"forks_count":52,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-15T23:31:26.540Z","etag":null,"topics":["amazon","amazon-spapi","mws","mws-api","mws-sdk","selling-partner-api","selling-partner-api-sdk","sp-api"],"latest_commit_sha":null,"homepage":"https://gopkg.me/selling-partner-api-sdk","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/amzapi.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,"publiccode":null,"codemeta":null}},"created_at":"2021-01-11T07:56:02.000Z","updated_at":"2024-10-28T13:05:21.000Z","dependencies_parsed_at":"2024-04-10T21:33:30.017Z","dependency_job_id":"e628e8d5-1583-4ac4-8210-b8e5862fd86f","html_url":"https://github.com/amzapi/selling-partner-api-sdk","commit_stats":null,"previous_names":["gopkg-dev/selling-partner-api-sdk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amzapi%2Fselling-partner-api-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amzapi%2Fselling-partner-api-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amzapi%2Fselling-partner-api-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amzapi%2Fselling-partner-api-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amzapi","download_url":"https://codeload.github.com/amzapi/selling-partner-api-sdk/tar.gz/refs/heads/master","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-spapi","mws","mws-api","mws-sdk","selling-partner-api","selling-partner-api-sdk","sp-api"],"created_at":"2024-08-03T07:00:50.970Z","updated_at":"2025-05-09T11:31:29.749Z","avatar_url":"https://github.com/amzapi.png","language":"Go","funding_links":[],"categories":["Docs"],"sub_categories":["Library"],"readme":"# Amazon's Selling Partner API (SP-API) Golang SDK\n\n[![Go Reference](https://pkg.go.dev/badge/gopkg.me/selling-partner-api-sdk.svg)](https://pkg.go.dev/gopkg.me/selling-partner-api-sdk)\n\n## Installation\n\n~~~~\ngo get -u github.com/amzapi/selling-partner-api-sdk\n~~~~\n\n## Progress\n                    \n* [X] authorization ([authorization-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/authorization-api-model/authorization.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/authorization-api/authorization.md))\n* [X] catalog ([catalog-items-api-model](https://github.com/amzn/selling-partner-api-docs/blob/main/references/catalog-items-api/catalogItemsV0.md) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/catalog-items-api/catalogItemsV0.md))\n* [X] fbaInbound ([fulfillment-inbound-api-model](https://github.com/amzn/selling-partner-api-docs/blob/main/references/fulfillment-inbound-api/fulfillmentInboundV0.md) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/fulfillment-inbound-api/fulfillmentInboundV0.md))\n* [X] fbaInventory ([fba-inventory-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/fba-inventory-api-model/fbaInventory.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/fba-inventory-api/fbaInventory.md))\n* [X] fbaOutbound ([fulfillment-outbound-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/fulfillment-outbound-api-model/fulfillmentOutbound_2020-07-01.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/fulfillment-outbound-api/fulfillmentOutbound_2020-07-01.md))\n* [X] feeds ([feeds-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/feeds-api-model/feeds_2021-06-30.json) [DOC](https://github.com/amzn/selling-partner-api-docs/tree/main/references/feeds-api))\n* [X] fees ([product-fees-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/product-fees-api-model/productFeesV0.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/product-fees-api/productFeesV0.md))\n* [X] finances ([finances-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/finances-api-model/financesV0.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/finances-api/financesV0.md))\n* [X] merchantFulfillment ([merchant-fulfillment-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/merchant-fulfillment-api-model/merchantFulfillmentV0.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/merchant-fulfillment-api/merchantFulfillmentV0.md))\n* [X] messaging ([messaging-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/messaging-api-model/messaging.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/messaging-api/messaging.md))\n* [X] notifications ([notifications-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/notifications-api-model/notifications.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/notifications-api/notifications.md))\n* [X] ordersV0 ([orders-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/orders-api-model/ordersV0.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/orders-api/ordersV0.md))\n* [X] productPricing ([product-pricing-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/product-pricing-api-model/productPricingV0.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/product-pricing-api/productPricingV0.md))\n* [X] reports ([reports-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/reports-api-model/reports_2020-09-04.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/reports-api/reports_2020-09-04.md))\n* [X] sales ([sales-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/sales-api-model/sales.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/sales-api/sales.md))\n* [X] sellers ([sellers-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/sellers-api-model/sellers.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/sellers-api/sellers.md))\n* [X] service ([services-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/services-api-model/services.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/services-api/services.md))\n* [X] shipping ([shipping-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/shipping-api-model/shipping.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/shipping-api/shipping.md))\n* [ ] smallAndLight ([fba-small-and-light-api](https://github.com/amzn/selling-partner-api-models/blob/main/models/fba-small-and-light-api-model/fbaSmallandLight.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/fba-small-and-light-api/fbaSmallandLight.md))\n* [X] solicitations ([solicitations-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/solicitations-api-model/solicitations.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/solicitations-api/solicitations.md))\n* [X] uploads ([uploads-api-model](https://github.com/amzn/selling-partner-api-models/blob/main/models/uploads-api-model/uploads_2020-11-01.json) [DOC](https://github.com/amzn/selling-partner-api-docs/blob/main/references/uploads-api/uploads_2020-11-01.md))\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"net/http\"\n\t\"net/http/httputil\"\n\t\n\tsp \"github.com/amzapi/selling-partner-api-sdk/pkg/selling-partner\"\n\t\"github.com/amzapi/selling-partner-api-sdk/sellers\"\n\n\t\"github.com/google/uuid\"\n\t\"github.com/pkg/errors\"\n)\n\nfunc main() {\n\t\n\tsellingPartner, err := sp.NewSellingPartner(\u0026sp.Config{\n\t\tClientID:     \"\u003cClientID\u003e\",\n\t\tClientSecret: \"\u003cClientSecret\u003e\",\n\t\tRefreshToken: \"\u003cRefreshToken\u003e\",\n\t})\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tendpoint := \"https://sellingpartnerapi-fe.amazon.com\"\n\n\tseller, err := sellers.NewClientWithResponses(endpoint,\n\t\tsellers.WithRequestBefore(func(ctx context.Context, req *http.Request) error {\n\t\t\treq.Header.Add(\"X-Amzn-Requestid\", uuid.New().String()) //tracking requests\n\t\t\terr = sellingPartner.AuthorizeRequest(req)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"sign error\")\n\t\t\t}\n\t\t\tdump, err := httputil.DumpRequest(req, true)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"DumpRequest Error\")\n\t\t\t}\n\t\t\tlog.Printf(\"DumpRequest = %s\", dump)\n\t\t\treturn nil\n\t\t}),\n\t\tsellers.WithResponseAfter(func(ctx context.Context, rsp *http.Response) error {\n\t\t\tdump, err := httputil.DumpResponse(rsp, true)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"DumpResponse Error\")\n\t\t\t}\n\t\t\tlog.Printf(\"DumpResponse = %s\", dump)\n\t\t\treturn nil\n\t\t}),\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tctx := context.Background()\n\t_, err = seller.GetMarketplaceParticipationsWithResponse(ctx)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n\n```\n\n#Report Decryption\nAmazon specification of version `2020-09-04` returns encrypted reports. To decrypt the reports you could use [the Decrypt function of the decryption package](./pkg/decryption/decryptor.go).\n### Test example\nThe test example uses `amzn.GetReportDocumentResponse` from [Amazon models](https://github.com/amzn/selling-partner-api-models/blob/main/models/reports-api-model/reports_2020-09-04.json#L137) and the \nDecrypt function to download, decrypt and dump report. \n```go\nfunc TestSellingPartnerGetReportDocumentThirdParty(t *testing.T) {\n\tsellingPartner, err := sp.NewSellingPartner(\u0026sp.Config{\n\t\tClientID:     \"***\",\n\t\tClientSecret: \"***\",\n\t\tRefreshToken: \"***\",\n\t})\n\n\tif err != nil {\n\t\tt.Fatal(\"Failed to create NewSellingPartner: \", err)\n\t}\n\n\treport, err := reports.NewClientWithResponses(spiHost,\n\t\treports.WithRequestBefore(func(ctx context.Context, req *http.Request) error {\n\t\t\terr = sellingPartner.AuthorizeRequest(req)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"sign error\")\n\t\t\t}\n\t\t\tdump, err := httputil.DumpRequest(req, true)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"DumpRequest Error\")\n\t\t\t}\n\t\t\tioutil.WriteFile(\"test-samples/3dumpedThirdPartyReqGetReports.txt\", dump, 0777)\n\t\t\treturn nil\n\t\t}),\n\t\treports.WithResponseAfter(func(ctx context.Context, rsp *http.Response) error {\n\t\t\tdump, err := httputil.DumpResponse(rsp, true)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"DumpResponse Error\")\n\t\t\t}\n\t\t\tioutil.WriteFile(\"test-samples/3dumpedThirdPartyRespGetReports.txt\", dump, 0777)\n\t\t\treturn nil\n\t\t}),\n\t)\n\tif err != nil {\n\t\tt.Fatal(\"Failed to create NewClientWithResponses: \", err)\n\t}\n\tctx := context.Background()\n\treportDocumentId := \"***\"\n\tresp, err := report.GetReportDocument(ctx, reportDocumentId)\n\tif err != nil {\n\t\tt.Fatal(\"Failed to make GetReportDocument request: \", err)\n\t}\n\tif resp.StatusCode \u003c 200 || resp.StatusCode \u003e 299 {\n\t\tt.Fatal(\"Service returned a status that isn't 2xx: \", resp.StatusCode)\n\t}\n\tdefer resp.Body.Close()\n\tvar bodyData []byte\n\tresp.Body.Read(bodyData)\n\tcontent, err := ioutil.ReadAll(resp.Body)\n\tif err != nil {\n\t\tt.Fatal(\"Failed to read GetReportDocument response body: \", err)\n\t}\n\tvar reportDocumentResp amzn.GetReportDocumentResponse\n\terr = json.Unmarshal(content, \u0026reportDocumentResp)\n\tif err != nil {\n\t\tt.Fatal(\"Failed to unmarshall GetReportDocument response: \", err)\n\t}\n\tif reportDocumentResp.Errors != nil {\n\t\tt.Fatal(\"Got errors in the GetReportDocument response: \", reportDocumentResp.Errors)\n\t}\n\trespWithDocContent, err := http.Get(reportDocumentResp.Payload.Url)\n\tif err != nil {\n\t\tt.Fatal(\"failed to make request to \"+reportDocumentResp.Payload.Url+\" : \", err)\n\t}\n\tif respWithDocContent.StatusCode \u003c 200 || respWithDocContent.StatusCode \u003e 299 {\n\t\tt.Fatal(\"Service returned a status that isn't 2xx: \", respWithDocContent.StatusCode)\n\t}\n\tdefer respWithDocContent.Body.Close()\n\n\treportContentBytes, err := ioutil.ReadAll(respWithDocContent.Body)\n\tif err != nil {\n\t\tt.Fatal(\"Failed to read Report content body: \", err)\n\t}\n\tioutil.WriteFile(\"test-samples/3_encrypted_\"+reportDocumentId+\"_\"+reportType+\"_report.txt\", reportContentBytes, 0777)\n\tdecryptedFilecontent, err := decryption.Decrypt(reportDocumentResp.Payload.EncryptionDetails.Key, reportDocumentResp.Payload.EncryptionDetails.InitializationVector, reportContentBytes)\n\tif err != nil {\n\t\tt.Fatal(\"Failed to decrypt file content: \", err)\n\t}\n\tioutil.WriteFile(\"test-samples/3_\"+reportDocumentId+\"_\"+reportType+\"_report.txt\", decryptedFilecontent, 0777)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famzapi%2Fselling-partner-api-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famzapi%2Fselling-partner-api-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famzapi%2Fselling-partner-api-sdk/lists"}