amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
612 stars 736 forks source link

Amazon SP-API responding with "invalid marketplaceIds provided" when patching package dimensions #4130

Closed Daniell-Green closed 2 months ago

Daniell-Green commented 2 months ago

Hello everyone!

I'm working on integrating the Amazon SP API to update item dimensions for a specific SKU. However, I'm encountering an error that states "invalid marketplaceIds provided" with no details.

I have verified that I'm passing the correct marketplace ID, but the error persists. Below is the minimal code I'm using to reproduce the issue:

from sp_api import ListingItems
from sp_api.base.marketplaces import Marketplaces
from sp_api.base import SellingApiException

class AmazonProductManager:
    def __init__(self, credentials: AmazonAuth, marketplace: Marketplaces = Marketplaces.DE):
        self.creds = credentials
        self.credentials = dict(
            refresh_token=self.creds.refresh_token,
            lwa_app_id=self.creds.lwa_app_id,
            lwa_client_secret=self.creds.lwa_client_secret,
            aws_secret_key=self.creds.aws_secret_key,
            aws_access_key=self.creds.aws_access_key,
            role_arn=self.creds.role_arn
        )
        self.marketplace = marketplace

    def update_item_dimensions(self, seller_id: str, sku: str,
                               item_dimensions: dict = None,
                               package_dimensions: dict = None):
        """Update item dimensions."""
        try:
            payload = {
                "productType": "PRODUCT",
                "requirements": "LISTING",
                "attributes": {
                    # Dimensions are added here
                }
            }

            if isinstance(item_dimensions, dict):
                if item_dimensions:
                    payload['attributes']['item_dimensions'] = item_dimensions

            if isinstance(package_dimensions, dict):
                if package_dimensions:
                    payload['attributes']['package_dimensions'] = package_dimensions

            response = ListingsItems(credentials=self.credentials,
                                     marketplace=self.marketplace).put_listings_item(
                sellerId=seller_id, sku=sku, body=payload)

            return response.payload
        except SellingApiException as e:
            print(f"Error updating item dimensions: {e}")
            return None

Details:

Request_body:

{'productType': 'PRODUCT',
 'requirements': 'LISTING',
 'MarketplaceId': 'A1PA6795UKMFR9',
 'MarketplaceIds': ['A1PA6795UKMFR9'],
 'marketplaceIds': ['A1PA6795UKMFR9'],
 'marketplace_ids': ['A1PA6795UKMFR9'],
 'attributes': {
    'package_dimensions': {
        'height': '19',
        'length': '108',
        'unit': 'CM',
        'weight': '28',
        'weight_unit': 'KG',
        'width': '67'}}
}

Response: Error updating item dimensions: [{'code': 'InvalidInput', 'message': "Invalid 'marketplaceIds' provided.", 'details': ''}]

What could be causing this error, and how can I resolve it? Any help would be greatly appreciated!

mafge commented 2 months ago

Hi @Daniell-Green, thanks for reaching out! Please note that marketplaceIds needs to be submitted in the query parameters and not in the body. In your case you have to explicitly provide marketplaceId in the put_listings_item call. Hope that helps! Thanks, Marc Selling Partner Developer Services

Daniell-Green commented 2 months ago

Thank you, that worked :)

Daniell-Green commented 2 months ago

resolved!