v6.0.0
Warning
This version of the library is only compatible with PHP >=8.1.
This major release is a complete overhaul of the library. There is basically no code left at all from v5
.
A quick summary of the big changes:
- The code generation process is now contained inside this repository, which should make it much easier for people to contribute. Previously, all code generation happened in a separate, private repository, because it was messy, and publishing the codegen setup in that state would have done more harm than good. Now, anyone can easily generate the code for the library from scratch.
- The entire auth/request/response process is based on Saloon. The actual code generation uses
highsidelabs/saloon-sdk-generator
, which is a fork ofcrescat-io/saloon-sdk-generator
. - The structure and naming conventions of the classes and attributes in this library have been made as similar to the names in Amazon's documentation as possible. As a result, I've removed the
docs/
section entirely, because a) the old documentation was often incomplete and/or misleading, and b) once you have a basic grasp of how this library works now, Amazon's documentation will tell you everything you need to know.
All the functionality of v5
is still present: full API coverage, automatic RDT generation, document upload/download support. The syntax has changed somewhat, but the concepts are the same. It's now easier to access request and response internals, since all requests/responses have all the functionality of any other Saloon request or response.
Upgrade guide
-
The
Configuration
class has been replaced with theSellingPartnerApi
class. This:$config = new SellingPartnerApi\Configuration([ "lwaClientId" => "<LWA client ID>", "lwaClientSecret" => "<LWA client secret>", "lwaRefreshToken" => "<LWA refresh token>", "awsAccessKeyId" => "<AWS access key ID>", "awsSecretAccessKey" => "<AWS secret access key>", // If you're not working in the North American marketplace, change // this to another endpoint from lib/Endpoint.php "endpoint" => SellingPartnerApi\Endpoint::NA, ]);
Now looks like this:
$connector = SellingPartnerApi::make( clientId: 'amzn1.application-oa2-client.asdfqwertyuiop...', clientSecret: 'amzn1.oa2-cs.v1.1234567890asdfghjkl...', refreshToken: 'Atzr|IwEBIA...', endpoint: Endpoint::NA, // Or Endpoint::EU, Endpoint::FE, Endpoint::NA_SANDBOX, etc. );
-
To access a particular API, rather than directly instantiating an API class, like this:
$reportsApi = new ReportsV20210630Api($config); $dfOrdersApi = new VendorDirectFulfillmentOrdersV1Api($config);
Do this:
$reportsApi = $connector()->seller()->reports(); $dfOrdersApi = $connector()->vendor()->directFulfillmentOrders();
-
To call an endpoint:
$response = $reportsApi->getReports( reportTypes: ['GET_MERCHANT_ALL_LISTINGS'], marketplaceIds: ['ATVPDKIKX0DER'], createdAfter: new DateTime('2024-03-01'), ); $json = $response->json(); $reports = $response->dto(); // A structured DTO
What was previously referred to as models are now called DTOs. DTOs are required to make
POST
/PUT
/PATCH
requests, similarly to how models were required for those sorts of create/update operations inv5
. For an example of how to use a DTO to make aPOST
request, see the Working with DTOs section of the README. -
To specify which data elements you want to retrieve when calling restricted endpoints (
getOrder
,getOrders
, andgetOrderItems
), pass an additionaldataElements
parameter toSellingPartnerApi::make()
rather than passing the$data_elements
parameter to the restricted endpoint itself.
Any other questions about upgrading should be answerable using the README, but if you have any questions, feel free to open a discussion :)