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

Update country_of_origin using Patch request on listing items api #821

Open
greenhof opened this issue Nov 19, 2024 · 1 comment
Open

Update country_of_origin using Patch request on listing items api #821

greenhof opened this issue Nov 19, 2024 · 1 comment

Comments

@greenhof
Copy link

Problem description:

I am banging my head on replacing country_of_origin attribute on multiple listings. Could you please take a look at my code and point me in the right direction?

Error:

"errors": [
    {
      "code": "InvalidInput",
      "message": "Invalid empty value provided in patch at index of 0.",
      "details": ""
    }
  ]

Code

$data = new ListingsItemPatchRequest(
          $productType,
          [
              new PatchOperation(
                  'replace',
                  '/attributes/country_of_origin',
                  [
                  
                          'value' => $cocs[$sku],
                          'marketplace_id' => $mplaceKurz[$code],

                    
                  ]
                  
              ),
          ]
          
      );
 $patchresult = $listingsItemsApi->patchListingsItem('A2XXXXXXX',$sku, $data, array($mplaceKurz[$code]));

here is the generated request body:

SellingPartnerApi\Seller\ListingsItemsV20210801\Dto\ListingsItemPatchRequest Object
(
[productType] => BEAUTY
[patches] => Array
(
[0] => SellingPartnerApi\Seller\ListingsItemsV20210801\Dto\PatchOperation Object
(
[op] => replace
[path] => /attributes/country_of_origin
[value] => Array
(
[value] => DE
[marketplace_id] => AMEN7PMS3EDWL
)

            )

    )

)

@jlevers
Copy link
Owner

jlevers commented Nov 21, 2024

The value typically has to be a nested array, because there are some attributes that can have multiple values. Give this a shot:

$data = new ListingsItemPatchRequest(
    $productType,
    [
        new PatchOperation(
                'replace',
                '/attributes/country_of_origin',
                [[
                    'value' => $cocs[$sku],
                    'marketplace_id' => $mplaceKurz[$code],
                ]]
            ),
        ]
);
$patchresult = $listingsItemsApi->patchListingsItem('A2XXXXXXX', $sku, $data, [$mplaceKurz[$code]]);

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