amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
580 stars 730 forks source link

Authorization using Swagger generated PHP client #708

Closed antonkorotkov closed 3 years ago

antonkorotkov commented 3 years ago

Hi there.

I understand we can generate PHP (or whatever) language client library using Models JSON. That is clear and I was able to generate it using swagger-codegen. Specifically, I have generated Authorization and Orders APIs in the same library folder assuming they will work in conjunction.

My confusion is around how the Authorization API is connected to any other APIs(Orders in my case). I understand that requests should be singed but in the generated Orders API code I don't see where it happens and don't see any documentation related to this.

Does anybody have any success using Swagger generated library for PHP? Any suggestions from Amazon Support?

Thanks.

charliecode commented 3 years ago

Hello @antonkorotkov. In regards to the authorization API, it's use is stated in the "description" part of the models json. It states "With the getAuthorizationCode operation, you can request a Login With Amazon (LWA) authorization code that will allow you to call a Selling Partner API on behalf of a seller who has already authorized you to call Amazon Marketplace Web Service (Amazon MWS). You specify a developer ID, an MWS auth token, and a seller ID. Taken together, these represent the Amazon MWS authorization that the seller previously granted you. The operation returns an LWA authorization code that can be exchanged for a refresh token and access token representing authorization to call the Selling Partner API on the seller's behalf. By using this API, sellers who have already authorized you for Amazon MWS do not need to re-authorize you for the Selling Partner API."

As for the docs for connecting to the SP-API, you can find them here.

antonkorotkov commented 3 years ago

Hello @antonkorotkov. In regards to the authorization API, it's use is stated in the "description" part of the models json. It states "With the getAuthorizationCode operation, you can request a Login With Amazon (LWA) authorization code that will allow you to call a Selling Partner API on behalf of a seller who has already authorized you to call Amazon Marketplace Web Service (Amazon MWS). You specify a developer ID, an MWS auth token, and a seller ID. Taken together, these represent the Amazon MWS authorization that the seller previously granted you. The operation returns an LWA authorization code that can be exchanged for a refresh token and access token representing authorization to call the Selling Partner API on the seller's behalf. By using this API, sellers who have already authorized you for Amazon MWS do not need to re-authorize you for the Selling Partner API."

As for the docs for connecting to the SP-API, you can find them here.

Thank you, I did find this of course, and have read several times but it describes how things are working in general. Where can I find a specific code example using Swagger generated client for PHP? That is my main question.

charliecode commented 3 years ago

@antonkorotkov That's the point for things like swagger-codegen or openapi-generator. They generate the client for you and then you call the API through that client. You're not going to find any step by step documentation specifically from Amazon on exactly how to call the particular function you need. You'll need to use the docs which can be created with the models JSON file. Then look through the read me file and some times the actual generated code and put it all together yourself. You would probably be better served looking through swagger-codegen or openapi-generator docs as that question is more related towards the actual code generator.

antonkorotkov commented 3 years ago

@charliecode so, it sounds like swagger-codegen generates a bare minimum to implement the basics described in JSON and all the rest should be developed additionally directly to the generated code?

Anyway, thanks. We have decided to stick with MWS API for now.

charliecode commented 3 years ago

@antonkorotkov Yes, the generated client is bare bones. It's not a SDK in the true sense of the word, which handles all of your authentication, access token generation and aws4 signing. These things must be added by the developer. Although I've been told Amazon does plan on providing SDK's in the most popular languages in the future. You can see that stated in issue amzn/selling-partner-api-models#684.