Closed jprojects closed 2 years ago
This is in fact answered in the api docs repository here: https://github.com/amzn/selling-partner-api-models/issues/1496
@chapmanjw wrote:
You can find more details on how to use the Listings Items APIs in the use case guide: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/listings-items-api-use-case-guide/listings-items-api-use-case-guide_2020-09-01.md.
The structure and data requirements for the attributes are provided by the Product Type Definitions API: https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/product-type-definitions-api-use-case-guide/definitions-product-types-api-use-case-guide_2020-09-01.md
The Product Type Definitions API provides JSON Schemas describing the listings attributes data for a given Amazon product type.
@jprojects, did @stefnats answer get you what you needed?
Thanks for the answers, but not quite at all I am a bit confused at this point, the documentation says "JSON object containing element attribute of structured lists data keyed by attribute name", but I need to know wich is the json schema and attribute names that the Amazon API expects In the docs the example request is incomplete, that's why it asked for a working example.
I don't have a working example as I've never had a need to call that endpoint, but when you call the Product Types API that @stefnats linked to above, one of the items in the response (the schema
attribute of the response) is a link to a JSON document that lists all the allowed attributes of that product type and all their allowed values (if the values are enumerable).
Assuming you're using this library to make the request, you then create an associative array that maps the product attributes discovered in the schema to the values you want to set them to, and pass that array of attributes => values
in as the value for the attributes
key on the ListingsItemPutRequest
object.
Thanks thats what I need ;)
Great :)
Thanks thats what I need ;)
@jprojects were you able to create a working example of this?
i tried creating a simple associative array and then passing the values to it in the listingItemPutRequest setAttributes setter.
$attributes = [
"list_price" => (float)$list_price,
"currency" => "USD",
"condition_type" => 'new',
"item_name" => $item_name,
"merchant_suggested_asin" => $asin,
"fulfillment_channel_code" => 'DEFAULT',
"quantity" => 0,
// ... additional attributes as needed, each keyed directly to its value ...
];
$listing_class = new ListingsV20210801Api($this->config);
$body = new ListingsItemPutRequest();
$body->setProductType($product_type);
$body->setRequirements('LISTING_PRODUCT_ONLY');
$body->setAttributes($attributes);
$result = $listing_class->putListingsItem($seller_id, $sku, $this->marketplace_ids, $body, $issue_locale = null);
Please do share some help here if you were able to understand how it works.
@rehmankhalil1001 Did you manage to get it running? To this day, there are no examples or proper documentation in the api description.
@rehmankhalil1001 Did you manage to get it running? To this day, there are no examples or proper documentation in the api description.
I did not get a chance to complete this, but from my understanding of it, we need to do the following:
here is a code snippet to get the product types and get the product schema for the chosen type:
`// Method to fetch product types from Amazon public function fetchProductTypes() { $apiInstance = new ProductTypeDefinitionsV20200901Api($this->config); $marketplace_ids = $this->marketplace_ids; // Assuming marketplace IDs are already set
try {
$result = $apiInstance->searchDefinitionsProductTypes($marketplace_ids);
return $result->getProductTypes(); // Assuming this returns an array of product types
} catch (\Exception $e) {
echo 'Exception when calling ProductTypeDefinitionsV20200901Api->searchDefinitionsProductTypes: ', $e->getMessage(), PHP_EOL;
// Consider returning an empty array or handling the exception as needed
return [];
}
}`
` public function fetchProductTypeSchema($product_type) { $apiInstance = new ProductTypeDefinitionsV20200901Api($this->config); $marketplace_ids = $this->marketplace_ids; // Assuming this is already set $seller_id = ''; // Replace with actual seller ID $product_type_version = 'LATEST'; $requirements = 'LISTING'; $requirements_enforced = 'ENFORCED'; $locale = 'DEFAULT';
try {
$result = $apiInstance->getDefinitionsProductType(
$product_type, $marketplace_ids, $seller_id, $product_type_version,
$requirements, $requirements_enforced, $locale
);
return $result; // This will return the schema for the product type
} catch (Exception $e) {
echo 'Exception when calling ProductTypeDefinitionsV20200901Api->getDefinitionsProductType: ', $e->getMessage(), PHP_EOL;
return null;
}
} `
then you need to use the schema returned that shows the required and optional attributes to be set to create a put request:
something like this:
` // Simple associative array for attributes // Structuring attributes based on the schema $attributes = [ "list_price" => [ [ "currency" => "USD", "marketplace_id" => $marketplace_id, "value" => (float)$list_price ] ], "condition_type" => [ [ "marketplace_id" => $marketplace_id, "value" => "new_new" ] ], "item_name" => [ [ "language_tag" => "en_US", "marketplace_id" => $marketplace_id, "value" => $item_name ] ], "merchant_suggested_asin" => [ [ "marketplace_id" => $marketplace_id, "value" => $asin ] ], "fulfillment_availability" => [ [ "fulfillment_channel_code" => "DEFAULT", "quantity" => 0, // Include additional fields like lead_time_to_ship_max_days, restock_date, etc. if applicable ] ], "brand" => [ [ "language_tag" => "en_US", "marketplace_id" => $marketplace_id, "value" => "YourBrandName" ] ], "bullet_point" => [ [ "language_tag" => "en_US", "marketplace_id" => $marketplace_id, "value" => "Edible food" // Example bullet point ] // ... Add more bullet points if needed ... ], "country_of_origin" => [ [ "marketplace_id" => $marketplace_id, "value" => "US" // Example country of origin ] ], "item_type_keyword" => [ [ "marketplace_id" => $marketplace_id, "value" => "FoodItem" // Example item type keyword ] ], "product_description" => [ [ "language_tag" => "en_US", "marketplace_id" => $marketplace_id, "value" => "Your product description here." // Replace with actual product description ] ], "supplier_declared_dg_hz_regulation" => [ [ "marketplace_id" => $marketplace_id, "value" => "not_applicable" // Assuming it's not a hazardous material ] ], "parentage_level" => [ [ "marketplace_id" => $marketplace_id, "value" => "parent" // Specify as 'parent' or 'child' based on your product ] ], // ... additional attributes as needed ... ];
$listing_class = new ListingsV20210801Api($this->config);
$body = new ListingsItemPutRequest();
$body->setProductType($product_type);
$body->setRequirements('LISTING_PRODUCT_ONLY');
$body->setAttributes($attributes);
$result = $listing_class->putListingsItem($seller_id, $sku, $this->marketplace_ids, $body, $issue_locale = null);`
@rehmankhalil1001 Thank you very much! How did you find out about structuring the attributes? In particular, list_price caught my attention, as this is what I've found:
'purchasable_offer' => [[
'currency' => $currency,
'start_at' => [
'value' => (new DateTimeImmutable())->format('c')
],
'our_price' => [[
'schedule' => [[
'value_with_tax' => $price,
]]
]],
'marketplace_id' => $seller->getMarketplaceId()
]]
@rkrx if you are planning to update the price only, I would recommend you to use the patch listings API from Amazon instead: https://developer-docs.amazon.com/sp-api/docs/listings-items-api-v2021-08-01-reference#patchlistingsitem
you can read more about that on this thread: https://github.com/amzn/selling-partner-api-models/issues/419
you can also use the feeds API to do this: https://github.com/jlevers/selling-partner-api/issues/561
@rehmankhalil1001 if you are planning to update the price only, I would recommend you to use the patch listings API from Amazon instead
I need to get feedback from the API as to whether the processing was successful and I can't easily use the Notifications API
yet. Therefore I will migrate from POST_FLAT_FILE_INVLOADER_DATA
and POST_PRODUCT_DATA
to JSON_LISTINGS_FEED
directly (Feeds API). You'll get a Resultfeed after the processing is done.
There is also a limit on how many feeds of the same type can be processed at the same time. Therefore I will try to keep everything together. The Attributes are the same in any szenario, but they are different for POST_FLAT_FILE_INVLOADER_DATA
/POST_PRODUCT_DATA
and the new JSON_LISTINGS_FEED
.
Could someone show me an example of how to build the body for the ListingsItemPutRequest function I'm stuck at this point