All Projects → amzapi → selling-partner-api-sdk

amzapi / selling-partner-api-sdk

Licence: MIT license
Golang toolkit for working with Amazon's Selling Partner API (SP-API)

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to selling-partner-api-sdk

amz sp api
AmzSpApi - Unofficial Ruby gem for the Selling Partner APIs (SP-API)
Stars: ✭ 22 (-54.17%)
Mutual labels:  amazon, mws-api, mws, mws-sdk, sp-api, selling-partner-api, selling-partner-api-sdk
selling-partner-sdk
Amazon Selling Partner JAVA SDK SP API
Stars: ✭ 15 (-68.75%)
Mutual labels:  amazon, mws, sp-api, selling-partner-api
Amazon-SP-API-CSharp
.Net C# library for the new Amazon Selling Partner API
Stars: ✭ 95 (+97.92%)
Mutual labels:  amazon, mws-api, selling-partner-api, selling-partner-api-sdk
sp-api-sdk
Amazon Selling Partner SPI - PHP SDKs
Stars: ✭ 34 (-29.17%)
Mutual labels:  amazon, mws, mws-sdk, selling-partner-api
amazon-mws-api-sdk
Amazon MWS API TypeScript and Node.js Unofficial SDK
Stars: ✭ 19 (-60.42%)
Mutual labels:  mws-api, mws, mws-sdk
mws-product
A module for retrieving product information via Amazon MWS API
Stars: ✭ 40 (-16.67%)
Mutual labels:  amazon, mws
mws-sdk
JavaScript SDK for Amazon Marketplace Web Services (MWS)
Stars: ✭ 23 (-52.08%)
Mutual labels:  amazon, mws
Knative Lambda Runtime
Running AWS Lambda Functions on Knative/Kubernetes Clusters
Stars: ✭ 201 (+318.75%)
Mutual labels:  amazon
Laravel Aws Eb
Ready-to-deploy configuration to run Laravel on AWS Elastic Beanstalk.
Stars: ✭ 247 (+414.58%)
Mutual labels:  amazon
Upic
📤uPic is a native, powerful, beautiful and simple picture and file upload tool for macOS.
Stars: ✭ 2,465 (+5035.42%)
Mutual labels:  amazon
Lector
An API for your Kindle data
Stars: ✭ 177 (+268.75%)
Mutual labels:  amazon
Alexaskillskit.net
.NET library that simplifies Alexa skills development; same object model as Amazon's AlexaSkillsKit for Java
Stars: ✭ 210 (+337.5%)
Mutual labels:  amazon
Alfred Web Search Suggest
Alfred search suggest workflow for various popular websites.
Stars: ✭ 249 (+418.75%)
Mutual labels:  amazon
Aws Lambda Fastify
Insipired by aws-serverless-express to work with Fastify with inject functionality.
Stars: ✭ 190 (+295.83%)
Mutual labels:  amazon
node-red-contrib-sonospollytts
Play speech TTS using Sonos.
Stars: ✭ 11 (-77.08%)
Mutual labels:  amazon
Home Assistant
Home-Assistant-Config
Stars: ✭ 182 (+279.17%)
Mutual labels:  amazon
google-aws-federator
A small command line tool to help manage AWS Federated Identities authenticated through Google Apps
Stars: ✭ 29 (-39.58%)
Mutual labels:  amazon
privacy-settings
Guide to privacy settings for most major softwares and services.
Stars: ✭ 97 (+102.08%)
Mutual labels:  amazon
Utern
Multi group and stream log tailing for AWS CloudWatch Logs.
Stars: ✭ 241 (+402.08%)
Mutual labels:  amazon
S3sync
Really fast sync tool for S3
Stars: ✭ 224 (+366.67%)
Mutual labels:  amazon

Amazon's Selling Partner API (SP-API) Golang SDK

Go Reference

Installation

go get -u gopkg.me/selling-partner-api-sdk

Progress

Example

package main

import (
	"context"
	"log"
	"net/http"
	"net/http/httputil"
	
	sp "gopkg.me/selling-partner-api-sdk/pkg/selling-partner"
	"gopkg.me/selling-partner-api-sdk/sellers"

	"github.com/google/uuid"
	"github.com/pkg/errors"
)

func main() {
	
	sellingPartner, err := sp.NewSellingPartner(&sp.Config{
		ClientID:     "<ClientID>",
		ClientSecret: "<ClientSecret>",
		RefreshToken: "<RefreshToken>",
		AccessKeyID: "<AWS IAM User Access Key Id>",
		SecretKey:   "<AWS IAM User Secret Key>",
		Region:      "<AWS Region>",
		RoleArn:     "<AWS IAM Role ARN>",
	})

	if err != nil {
		panic(err)
	}

	endpoint := "https://sellingpartnerapi-fe.amazon.com"

	seller, err := sellers.NewClientWithResponses(endpoint,
		sellers.WithRequestBefore(func(ctx context.Context, req *http.Request) error {
			req.Header.Add("X-Amzn-Requestid", uuid.New().String()) //tracking requests
			err = sellingPartner.SignRequest(req)
			if err != nil {
				return errors.Wrap(err, "sign error")
			}
			dump, err := httputil.DumpRequest(req, true)
			if err != nil {
				return errors.Wrap(err, "DumpRequest Error")
			}
			log.Printf("DumpRequest = %s", dump)
			return nil
		}),
		sellers.WithResponseAfter(func(ctx context.Context, rsp *http.Response) error {
			dump, err := httputil.DumpResponse(rsp, true)
			if err != nil {
				return errors.Wrap(err, "DumpResponse Error")
			}
			log.Printf("DumpResponse = %s", dump)
			return nil
		}),
	)

	if err != nil {
		panic(err)
	}

	ctx := context.Background()
	_, err = seller.GetMarketplaceParticipationsWithResponse(ctx)

	if err != nil {
		panic(err)
	}
}

#Report Decryption Amazon specification of version 2020-09-04 returns encrypted reports. To decrypt the reports you could use the Decrypt function of the decryption package.

Test example

The test example uses amzn.GetReportDocumentResponse from Amazon models and the Decrypt function to download, decrypt and dump report.

func TestSellingPartnerGetReportDocumentThirdParty(t *testing.T) {
	sellingPartner, err := sp.NewSellingPartner(&sp.Config{
		ClientID:     "***",
		ClientSecret: "***",
		RefreshToken: "***",
		AccessKeyID:  "***",
		SecretKey:    "***",
		Region:       "***",
		RoleArn:      "***",
	})

	if err != nil {
		t.Fatal("Failed to create NewSellingPartner: ", err)
	}

	report, err := reports.NewClientWithResponses(spiHost,
		reports.WithRequestBefore(func(ctx context.Context, req *http.Request) error {
			err = sellingPartner.SignRequest(req)
			if err != nil {
				return errors.Wrap(err, "sign error")
			}
			dump, err := httputil.DumpRequest(req, true)
			if err != nil {
				return errors.Wrap(err, "DumpRequest Error")
			}
			ioutil.WriteFile("test-samples/3dumpedThirdPartyReqGetReports.txt", dump, 0777)
			return nil
		}),
		reports.WithResponseAfter(func(ctx context.Context, rsp *http.Response) error {
			dump, err := httputil.DumpResponse(rsp, true)
			if err != nil {
				return errors.Wrap(err, "DumpResponse Error")
			}
			ioutil.WriteFile("test-samples/3dumpedThirdPartyRespGetReports.txt", dump, 0777)
			return nil
		}),
	)
	if err != nil {
		t.Fatal("Failed to create NewClientWithResponses: ", err)
	}
	ctx := context.Background()
	reportDocumentId := "***"
	resp, err := report.GetReportDocument(ctx, reportDocumentId)
	if err != nil {
		t.Fatal("Failed to make GetReportDocument request: ", err)
	}
	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		t.Fatal("Service returned a status that isn't 2xx: ", resp.StatusCode)
	}
	defer resp.Body.Close()
	var bodyData []byte
	resp.Body.Read(bodyData)
	content, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		t.Fatal("Failed to read GetReportDocument response body: ", err)
	}
	var reportDocumentResp amzn.GetReportDocumentResponse
	err = json.Unmarshal(content, &reportDocumentResp)
	if err != nil {
		t.Fatal("Failed to unmarshall GetReportDocument response: ", err)
	}
	if reportDocumentResp.Errors != nil {
		t.Fatal("Got errors in the GetReportDocument response: ", reportDocumentResp.Errors)
	}
	respWithDocContent, err := http.Get(reportDocumentResp.Payload.Url)
	if err != nil {
		t.Fatal("failed to make request to "+reportDocumentResp.Payload.Url+" : ", err)
	}
	if respWithDocContent.StatusCode < 200 || respWithDocContent.StatusCode > 299 {
		t.Fatal("Service returned a status that isn't 2xx: ", respWithDocContent.StatusCode)
	}
	defer respWithDocContent.Body.Close()

	reportContentBytes, err := ioutil.ReadAll(respWithDocContent.Body)
	if err != nil {
		t.Fatal("Failed to read Report content body: ", err)
	}
	ioutil.WriteFile("test-samples/3_encrypted_"+reportDocumentId+"_"+reportType+"_report.txt", reportContentBytes, 0777)
	decryptedFilecontent, err := decryption.Decrypt(reportDocumentResp.Payload.EncryptionDetails.Key, reportDocumentResp.Payload.EncryptionDetails.InitializationVector, reportContentBytes)
	if err != nil {
		t.Fatal("Failed to decrypt file content: ", err)
	}
	ioutil.WriteFile("test-samples/3_"+reportDocumentId+"_"+reportType+"_report.txt", decryptedFilecontent, 0777)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].