1. Go to this page and download the library: Download jlevers/selling-partner-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jlevers / selling-partner-api example snippets
use SellingPartnerApi\SellingPartnerApi;
use SellingPartnerApi\Enums\Endpoint;
$connector = SellingPartnerApi::seller(
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.
);
use SellingPartnerApi\SellingPartnerApi;
$reportType = 'GET_MERCHANT_LISTINGS_DATA';
// Assume we already got a report document ID from a previous getReport call
$documentId = '1234567890.asdf';
$connector = SellingPartnerApi::seller(/* ... */);
$response = $connector->reportsV20210630()->getReportDocument($documentId, $reportType);
$reportDocument = $response->dto();
/*
* - Array of arrays, where each sub array corresponds to a row of the report, if this is a TSV, CSV, or XLSX report
* - A nested associative array (from json_decode) if this is a JSON report
* - The raw report data if this is a TXT or PDF report
* - A SimpleXMLElement object if this is an XML report
*/
$contents = $reportDocument->download($reportType);
$streamContents = $reportDocument->downloadStream(); // The raw report stream
use SellingPartnerApi\Seller\FeedsV20210630\Dto\CreateFeedDocumentSpecification;
use SellingPartnerApi\Seller\FeedsV20210630\Dto\CreateFeedSpecification;
use SellingPartnerApi\Seller\FeedsV20210630\Responses\CreateFeedDocumentResponse;
$feedType = 'POST_PRODUCT_PRICING_DATA';
$connector = SellingPartnerApi::seller(/* ... */);
$feedsApi = $connector->feedsV20210630();
// Create feed document
$contentType = CreateFeedDocumentResponse::getContentType($feedType);
$createFeedDoc = new CreateFeedDocumentSpecification($contentType);
$createDocumentResponse = $feedsApi->createFeedDocument($createFeedDoc);
$feedDocument = $createDocumentResponse->dto();
// Upload feed contents to document
$feedContents = file_get_contents('your/feed/file.xml');
$feedDocument->upload($feedType, $feedContents);
$createFeedSpec = new CreateFeedSpecification(
marketplaceIds: ['ATVPDKIKX0DER'],
inputFeedDocumentId: $feedDocument->feedDocumentId,
feedType: $feedType,
);
// Create feed with the feed document we just uploaded
$createFeedResponse = $feedsApi->createFeed($createFeedSpec);
$feedId = $createFeedResponse->dto()->feedId;
use SellingPartnerApi\SellingPartnerApi;
$feedType = 'POST_PRODUCT_PRICING_DATA';
// Assume we already got a feed result document ID from a previous getFeed call
$documentId = '1234567890.asdf';
$connector = SellingPartnerApi::seller(/* ... */);
$response = $connector->feedsV20210630()->getFeedDocument($documentId);
$feedDocument = $response->dto();
$contents = $feedResultDocument->download($feedType);
use SellingPartnerApi\Enums\Marketplace;
use SellingPartnerApi\OAuth;
$oauth = new OAuth(
clientId: 'amzn1.application-oa2-client.asdfqwertyuiop...',
clientSecret: 'amzn1.oa2-cs.v1.1234567890asdfghjkl...',
redirectUri: 'https://example.com/redirect',
);
$authUrl = $oauth->getAuthorizationUri(
appId: 'amzn1.sp.solution...',
state: 'unique-base64-encoded-string',
// The marketplace that you want to authorize the seller in
marketplace: Marketplace::US,
// If your app is published on the Marketplace Appstore, pass this parameter:
// draftApp: false,
);
// Redirect your user to $authUrl...
use SellingPartnerApi\OAuth;
// Parse query parameters from inbound Amazon request...
$authCode = $query['spapi_oauth_code'];
$oauth = new OAuth(
clientId: 'amzn1.application-oa2-client.asdfqwertyuiop...',
clientSecret: 'amzn1.oa2-cs.v1.1234567890asdfghjkl...',
redirectUri: 'https://example.com/redirect',
);
$refreshToken = $oauth->getRefreshToken($authCode);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.