1

I'm bulk-creating items using the bulkCreateOrReplaceInventoryItem API. Some of my products are listed under the wrong categories. I can't find any field in the request payload by which I can mention the category id of each item.

Here are the API docs: https://developer.ebay.com/api-docs/sell/inventory/resources/inventory_item/methods/bulkCreateOrReplaceInventoryItem

Can anyone help me provide the category details while creating new items on eBay?

Here is my request payload:

foreach ($data as $key => $item) {
    $o = array(
        "sku" => $item['sku'],
        "locale" => $item['locale'],
        "product" => array(
            "title" => $item['title'],
            "description" => $item['description'],
            "aspects" => array(),
            "brand" => $item['brand'],
            "mpn" => $item['mpn'],
            "imageUrls" => $item['images'],
            "aspects" => $item['aspects']
        ),
        "condition" => $item['condition'],
        // "conditionDescription" => $item['conditionDescription'],
        "availability" => array(
            "shipToLocationAvailability" => array(
                "quantity" => $item['quantity']
            )
        ),
    );
    if ($item['condition'] != 'NEW') {
        $o['conditionDescription'] = $item['conditionDescription'];
    }
    $object[] = $o;
}
$object = array('requests' => $object);
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
habib
  • 1,454
  • 17
  • 31
  • To specify the category for each item, you need to include the categoryId field within the product object in your request payload. The categoryId represents the unique identifier of the category to which the item belongs – Hasan Raza Jun 28 '23 at 22:22

1 Answers1

0

you'd want to use the product field and specify the primaryProductCategory field to set the category for the item. The primaryProductCategory is a container that is used to identify the primary category in which the item will be listed on eBay.

foreach ($data as $key => $item) {
    $o = array(
        "sku" => $item['sku'],
        "locale" => $item['locale'],
        "product" => array(
            "title" => $item['title'],
            "description" => $item['description'],
            "aspects" => array(),
            "brand" => $item['brand'],
            "mpn" => $item['mpn'],
            "imageUrls" => $item['images'],
            "aspects" => $item['aspects'],
            "primaryProductCategory" => array(
                "categoryId" => $item['categoryId']
            )
        ),
        "condition" => $item['condition'],
        // "conditionDescription" => $item['conditionDescription'],
        "availability" => array(
            "shipToLocationAvailability" => array(
                "quantity" => $item['quantity']
            )
        ),
    );
    if ($item['condition'] != 'NEW') {
        $o['conditionDescription'] = $item['conditionDescription'];
    }
    $object[] = $o;
}
$object = array('requests' => $object);

In the above code, I added the primaryProductCategory array into the product array. You'll need to make sure that your $item array includes the categoryId key, and its value should be the ID of the category you want to list the item under. The value of categoryId should be a string.

Jenny
  • 172
  • 7