Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformers xml json for Selling Partner API for PHP #841

Open
carnevaleveneziano opened this issue Jan 8, 2025 · 1 comment
Open

Transformers xml json for Selling Partner API for PHP #841

carnevaleveneziano opened this issue Jan 8, 2025 · 1 comment

Comments

@carnevaleveneziano
Copy link

Hi,
i'm using your library Selling Partner API for PHP on github and i read about the passage from xml to json format.
I see that you've created the Transformers library that can convert easily the xml file to json file, but i don't understand than in which way i can send the json file through your selling partner api.
Until now to send xml for inventory data (asin quantity) files i call the library FeedsApi with feedtype POST_INVENTORY_AVAILABILITY_DATA, than i send the xml feed with $feedsApi->createFeed.
With your json transformers i see that the library will create a json file, but than in which way i must send the json to amazon with your sp-api php library?
Greetings

@jlevers
Copy link
Owner

jlevers commented Jan 8, 2025

The process for sending the JSON feed is exactly the same as the process for sending the XML feed – you just replace the feedtype in the call with JSON_LISTINGS_FEED:

// $oldFeedType = 'POST_INVENTORY_AVAILABILITY_DATA';
$feedType = 'JSON_LISTINGS_FEED';

$connector = SellingPartnerApi::seller(/* ... */);
$feedsApi = $connector->feedsV20210630();

// Create feed document
$contentType = CreateFeedDocumentResponse::getContentType($feedType);
$createFeedDoc = new CreateFeedDocumentSpecification($contentType);
$createDocumentResponse = $feedsApi->createFeedDocument($createFeedDoc);
$feedDocument = $createDocumentResponse->dto();

// Run transformer here:
$json = Transformer::fromFile(
    InventoryAvailability::$feedType,
    'your/feed/file.xml',
    'ATVPDKIKX0DER'
);
$feedContents = json_encode($json);
$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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants