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::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.
)->seller();
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::make(/* ... */)->seller();
$response = $connector->reports()->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::make(/* ... */)->seller();
$feedsApi = $connector->feeds();
// 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::make(/* ... */)->seller();
$response = $connector->feeds()->getFeedDocument($documentId);
$feedDocument = $response->dto();
$contents = $feedResultDocument->download($feedType);
use SellingPartnerApi\Seller\OrdersV0\Dto;
use SellingPartnerApi\SellingPartnerApi;
$confirmShipmentRequest = new Dto\ConfirmShipmentRequest(
packageDetail: new Dto\PackageDetail(
packageReferenceId: 'PKG123',
carrierCode: 'USPS',
trackingNumber: 'ASDF1234567890',
shipDate: new DateTime('2024-01-01 12:00:00'),
orderItems: [
new Dto\ConfirmShipmentOrderItem(
orderItemId: '1234567890',
quantity: 1,
),
new Dto\ConfirmShipmentOrderItem(
orderItemId: '0987654321',
quantity: 2,
)
],
),
marketplaceId: 'ATVPDKIKX0DER',
);
$response = $ordersApi->confirmShipment(
orderId: '123-4567890-1234567',
confirmShipmentRequest: $confirmShipmentRequest,
)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.